@@ -1,148 +1,148 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | if ( ! class_exists( 'WP_Super_Duper' ) ) { |
7 | 7 | |
8 | 8 | |
9 | - /** |
|
10 | - * A Class to be able to create a Widget, Shortcode or Block to be able to output content for WordPress. |
|
11 | - * |
|
12 | - * Should not be called direct but extended instead. |
|
13 | - * |
|
14 | - * Class WP_Super_Duper |
|
15 | - * @since 1.0.3 is_block_content_call() method added. |
|
16 | - * @since 1.0.3 Placeholder text will be shown for widget that return no block content. |
|
17 | - * @since 1.0.4 is_elementor_widget_output() method added. |
|
18 | - * @since 1.0.4 is_elementor_preview() method added. |
|
19 | - * @since 1.0.5 Block checkbox options are set as true by default even when set as false - FIXED |
|
20 | - * @since 1.0.6 Some refactoring for page builders - CHANGED |
|
21 | - * @since 1.0.7 Some refactoring for page builders - CHANGED |
|
22 | - * @since 1.0.8 Some refactoring for page builders ( cornerstone builder now supported ) - CHANGED |
|
23 | - * @since 1.0.9 Numbers saving as strings and not numbers which can cause block render issues on refresh - FIXED |
|
24 | - * @since 1.0.10 Some refactoring for page builders ( Avia builder for Enfold theme now supported ) - CHANGED |
|
25 | - * @since 1.0.11 Some refactoring for page builders - CHANGED |
|
26 | - * @ver 1.0.11 |
|
27 | - */ |
|
28 | - class WP_Super_Duper extends WP_Widget { |
|
29 | - |
|
30 | - public $version = "1.0.11"; |
|
31 | - public $block_code; |
|
32 | - public $options; |
|
33 | - public $base_id; |
|
34 | - public $arguments = array(); |
|
35 | - public $instance = array(); |
|
36 | - private $class_name; |
|
37 | - |
|
38 | - /** |
|
39 | - * Take the array options and use them to build. |
|
40 | - */ |
|
41 | - public function __construct( $options ) { |
|
42 | - global $sd_widgets; |
|
43 | - |
|
44 | - $sd_widgets[ $options['base_id'] ] = array( |
|
45 | - 'name' => $options['name'], |
|
46 | - 'class_name' => $options['class_name'] |
|
47 | - ); |
|
48 | - $this->base_id = $options['base_id']; |
|
49 | - // lets filter the options before we do anything |
|
50 | - $options = apply_filters( "wp_super_duper_options", $options ); |
|
51 | - $options = apply_filters( "wp_super_duper_options_{$this->base_id}", $options ); |
|
52 | - $options = $this->add_name_from_key( $options ); |
|
53 | - $this->options = $options; |
|
54 | - |
|
55 | - $this->base_id = $options['base_id']; |
|
56 | - $this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array(); |
|
57 | - |
|
58 | - // init parent |
|
59 | - parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] ); |
|
60 | - |
|
61 | - if ( isset( $options['class_name'] ) ) { |
|
62 | - // register widget |
|
63 | - $this->class_name = $options['class_name']; |
|
64 | - |
|
65 | - // register shortcode |
|
66 | - $this->register_shortcode(); |
|
67 | - |
|
68 | - // register block |
|
69 | - add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) ); |
|
70 | - } |
|
71 | - |
|
72 | - // add the CSS and JS we need ONCE |
|
73 | - global $sd_widget_scripts; |
|
74 | - |
|
75 | - if ( ! $sd_widget_scripts ) { |
|
76 | - wp_add_inline_script( 'admin-widgets', $this->widget_js() ); |
|
77 | - wp_add_inline_script( 'customize-controls', $this->widget_js() ); |
|
78 | - wp_add_inline_style( 'widgets', $this->widget_css() ); |
|
79 | - |
|
80 | - $sd_widget_scripts = true; |
|
81 | - |
|
82 | - // add shortcode insert button once |
|
83 | - add_action( 'media_buttons', array( $this, 'shortcode_insert_button' ) ); |
|
84 | - if ( $this->is_preview() ) { |
|
85 | - add_action( 'wp_footer', array( $this, 'shortcode_insert_button_script' ) ); |
|
86 | - // this makes the insert button work for elementor |
|
87 | - add_action( 'elementor/editor/after_enqueue_scripts', array( |
|
88 | - $this, |
|
89 | - 'shortcode_insert_button_script' |
|
90 | - ) ); // for elementor |
|
91 | - } |
|
92 | - // this makes the insert button work for cornerstone |
|
93 | - add_action('wp_print_footer_scripts',array( __CLASS__, 'maybe_cornerstone_builder' )); |
|
94 | - |
|
95 | - add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) ); |
|
96 | - add_action( 'wp_ajax_super_duper_get_picker', array( __CLASS__, 'get_picker' ) ); |
|
97 | - |
|
98 | - // add generator text to admin head |
|
99 | - add_action( 'admin_head', array( $this, 'generator' ) ); |
|
100 | - } |
|
101 | - |
|
102 | - do_action( 'wp_super_duper_widget_init', $options, $this ); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * Maybe insert the shortcode inserter button in the footer if we are in the cornerstone builder |
|
107 | - */ |
|
108 | - public static function maybe_cornerstone_builder(){ |
|
109 | - if(did_action('cornerstone_before_boot_app')){ |
|
110 | - self::shortcode_insert_button_script(); |
|
111 | - } |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * A function to ge the shortcode builder picker html. |
|
116 | - * |
|
117 | - * @param string $editor_id |
|
118 | - * |
|
119 | - * @return string |
|
120 | - */ |
|
121 | - public static function get_picker( $editor_id = '' ) { |
|
122 | - |
|
123 | - ob_start(); |
|
124 | - if ( isset( $_POST['editor_id'] ) ) { |
|
125 | - $editor_id = esc_attr( $_POST['editor_id'] ); |
|
126 | - } elseif ( isset( $_REQUEST['et_fb'] ) ) { |
|
127 | - $editor_id = 'main_content_content_vb_tiny_mce'; |
|
128 | - } |
|
129 | - |
|
130 | - global $sd_widgets; |
|
131 | - ?> |
|
9 | + /** |
|
10 | + * A Class to be able to create a Widget, Shortcode or Block to be able to output content for WordPress. |
|
11 | + * |
|
12 | + * Should not be called direct but extended instead. |
|
13 | + * |
|
14 | + * Class WP_Super_Duper |
|
15 | + * @since 1.0.3 is_block_content_call() method added. |
|
16 | + * @since 1.0.3 Placeholder text will be shown for widget that return no block content. |
|
17 | + * @since 1.0.4 is_elementor_widget_output() method added. |
|
18 | + * @since 1.0.4 is_elementor_preview() method added. |
|
19 | + * @since 1.0.5 Block checkbox options are set as true by default even when set as false - FIXED |
|
20 | + * @since 1.0.6 Some refactoring for page builders - CHANGED |
|
21 | + * @since 1.0.7 Some refactoring for page builders - CHANGED |
|
22 | + * @since 1.0.8 Some refactoring for page builders ( cornerstone builder now supported ) - CHANGED |
|
23 | + * @since 1.0.9 Numbers saving as strings and not numbers which can cause block render issues on refresh - FIXED |
|
24 | + * @since 1.0.10 Some refactoring for page builders ( Avia builder for Enfold theme now supported ) - CHANGED |
|
25 | + * @since 1.0.11 Some refactoring for page builders - CHANGED |
|
26 | + * @ver 1.0.11 |
|
27 | + */ |
|
28 | + class WP_Super_Duper extends WP_Widget { |
|
29 | + |
|
30 | + public $version = "1.0.11"; |
|
31 | + public $block_code; |
|
32 | + public $options; |
|
33 | + public $base_id; |
|
34 | + public $arguments = array(); |
|
35 | + public $instance = array(); |
|
36 | + private $class_name; |
|
37 | + |
|
38 | + /** |
|
39 | + * Take the array options and use them to build. |
|
40 | + */ |
|
41 | + public function __construct( $options ) { |
|
42 | + global $sd_widgets; |
|
43 | + |
|
44 | + $sd_widgets[ $options['base_id'] ] = array( |
|
45 | + 'name' => $options['name'], |
|
46 | + 'class_name' => $options['class_name'] |
|
47 | + ); |
|
48 | + $this->base_id = $options['base_id']; |
|
49 | + // lets filter the options before we do anything |
|
50 | + $options = apply_filters( "wp_super_duper_options", $options ); |
|
51 | + $options = apply_filters( "wp_super_duper_options_{$this->base_id}", $options ); |
|
52 | + $options = $this->add_name_from_key( $options ); |
|
53 | + $this->options = $options; |
|
54 | + |
|
55 | + $this->base_id = $options['base_id']; |
|
56 | + $this->arguments = isset( $options['arguments'] ) ? $options['arguments'] : array(); |
|
57 | + |
|
58 | + // init parent |
|
59 | + parent::__construct( $options['base_id'], $options['name'], $options['widget_ops'] ); |
|
60 | + |
|
61 | + if ( isset( $options['class_name'] ) ) { |
|
62 | + // register widget |
|
63 | + $this->class_name = $options['class_name']; |
|
64 | + |
|
65 | + // register shortcode |
|
66 | + $this->register_shortcode(); |
|
67 | + |
|
68 | + // register block |
|
69 | + add_action( 'admin_enqueue_scripts', array( $this, 'register_block' ) ); |
|
70 | + } |
|
71 | + |
|
72 | + // add the CSS and JS we need ONCE |
|
73 | + global $sd_widget_scripts; |
|
74 | + |
|
75 | + if ( ! $sd_widget_scripts ) { |
|
76 | + wp_add_inline_script( 'admin-widgets', $this->widget_js() ); |
|
77 | + wp_add_inline_script( 'customize-controls', $this->widget_js() ); |
|
78 | + wp_add_inline_style( 'widgets', $this->widget_css() ); |
|
79 | + |
|
80 | + $sd_widget_scripts = true; |
|
81 | + |
|
82 | + // add shortcode insert button once |
|
83 | + add_action( 'media_buttons', array( $this, 'shortcode_insert_button' ) ); |
|
84 | + if ( $this->is_preview() ) { |
|
85 | + add_action( 'wp_footer', array( $this, 'shortcode_insert_button_script' ) ); |
|
86 | + // this makes the insert button work for elementor |
|
87 | + add_action( 'elementor/editor/after_enqueue_scripts', array( |
|
88 | + $this, |
|
89 | + 'shortcode_insert_button_script' |
|
90 | + ) ); // for elementor |
|
91 | + } |
|
92 | + // this makes the insert button work for cornerstone |
|
93 | + add_action('wp_print_footer_scripts',array( __CLASS__, 'maybe_cornerstone_builder' )); |
|
94 | + |
|
95 | + add_action( 'wp_ajax_super_duper_get_widget_settings', array( __CLASS__, 'get_widget_settings' ) ); |
|
96 | + add_action( 'wp_ajax_super_duper_get_picker', array( __CLASS__, 'get_picker' ) ); |
|
97 | + |
|
98 | + // add generator text to admin head |
|
99 | + add_action( 'admin_head', array( $this, 'generator' ) ); |
|
100 | + } |
|
101 | + |
|
102 | + do_action( 'wp_super_duper_widget_init', $options, $this ); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * Maybe insert the shortcode inserter button in the footer if we are in the cornerstone builder |
|
107 | + */ |
|
108 | + public static function maybe_cornerstone_builder(){ |
|
109 | + if(did_action('cornerstone_before_boot_app')){ |
|
110 | + self::shortcode_insert_button_script(); |
|
111 | + } |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * A function to ge the shortcode builder picker html. |
|
116 | + * |
|
117 | + * @param string $editor_id |
|
118 | + * |
|
119 | + * @return string |
|
120 | + */ |
|
121 | + public static function get_picker( $editor_id = '' ) { |
|
122 | + |
|
123 | + ob_start(); |
|
124 | + if ( isset( $_POST['editor_id'] ) ) { |
|
125 | + $editor_id = esc_attr( $_POST['editor_id'] ); |
|
126 | + } elseif ( isset( $_REQUEST['et_fb'] ) ) { |
|
127 | + $editor_id = 'main_content_content_vb_tiny_mce'; |
|
128 | + } |
|
129 | + |
|
130 | + global $sd_widgets; |
|
131 | + ?> |
|
132 | 132 | |
133 | 133 | <div class="sd-shortcode-left-wrap"> |
134 | 134 | <?php |
135 | - asort( $sd_widgets ); |
|
136 | - if ( ! empty( $sd_widgets ) ) { |
|
137 | - echo '<select class="widefat" onchange="sd_get_shortcode_options(this);">'; |
|
138 | - echo "<option>" . __( 'Select shortcode' ) . "</option>"; |
|
139 | - foreach ( $sd_widgets as $shortcode => $class ) { |
|
140 | - echo "<option value='" . esc_attr( $shortcode ) . "'>" . esc_attr( $shortcode ) . " (" . esc_attr( $class['name'] ) . ")</option>"; |
|
141 | - } |
|
142 | - echo "</select>"; |
|
143 | - |
|
144 | - } |
|
145 | - ?> |
|
135 | + asort( $sd_widgets ); |
|
136 | + if ( ! empty( $sd_widgets ) ) { |
|
137 | + echo '<select class="widefat" onchange="sd_get_shortcode_options(this);">'; |
|
138 | + echo "<option>" . __( 'Select shortcode' ) . "</option>"; |
|
139 | + foreach ( $sd_widgets as $shortcode => $class ) { |
|
140 | + echo "<option value='" . esc_attr( $shortcode ) . "'>" . esc_attr( $shortcode ) . " (" . esc_attr( $class['name'] ) . ")</option>"; |
|
141 | + } |
|
142 | + echo "</select>"; |
|
143 | + |
|
144 | + } |
|
145 | + ?> |
|
146 | 146 | <div class="sd-shortcode-settings"></div> |
147 | 147 | |
148 | 148 | </div> |
@@ -153,8 +153,8 @@ discard block |
||
153 | 153 | <?php if ( $editor_id != '' ) { ?> |
154 | 154 | <button class="button sd-insert-shortcode-button" |
155 | 155 | onclick="sd_insert_shortcode(<?php if ( ! empty( $editor_id ) ) { |
156 | - echo "'" . $editor_id . "'"; |
|
157 | - } ?>)"><?php _e( 'Insert shortcode' ); ?></button> |
|
156 | + echo "'" . $editor_id . "'"; |
|
157 | + } ?>)"><?php _e( 'Insert shortcode' ); ?></button> |
|
158 | 158 | <?php } ?> |
159 | 159 | <button class="button" |
160 | 160 | onclick="sd_copy_to_clipboard()"><?php _e( 'Copy shortcode' ); ?></button> |
@@ -162,129 +162,129 @@ discard block |
||
162 | 162 | </div> |
163 | 163 | <?php |
164 | 164 | |
165 | - $html = ob_get_clean(); |
|
166 | - |
|
167 | - if ( wp_doing_ajax() ) { |
|
168 | - echo $html; |
|
169 | - $should_die = true; |
|
170 | - |
|
171 | - // some builder get the editor via ajax so we should not die on those ocasions |
|
172 | - $dont_die = array( |
|
173 | - 'parent_tag',// WP Bakery |
|
174 | - 'avia_request' // enfold |
|
175 | - ); |
|
176 | - |
|
177 | - foreach ( $dont_die as $request ) { |
|
178 | - if ( isset( $_REQUEST[ $request ] ) ) { |
|
179 | - $should_die = false; |
|
180 | - } |
|
181 | - } |
|
182 | - |
|
183 | - if ( $should_die ) { |
|
184 | - wp_die(); |
|
185 | - } |
|
186 | - |
|
187 | - } else { |
|
188 | - return $html; |
|
189 | - } |
|
190 | - |
|
191 | - return ''; |
|
192 | - |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * Output the version in the admin header. |
|
197 | - */ |
|
198 | - public function generator() { |
|
199 | - echo '<meta name="generator" content="WP Super Duper v' . $this->version . '" />'; |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * Get widget settings. |
|
204 | - * |
|
205 | - * @since 1.0.0 |
|
206 | - */ |
|
207 | - public static function get_widget_settings() { |
|
208 | - global $sd_widgets; |
|
209 | - |
|
210 | - $shortcode = isset( $_REQUEST['shortcode'] ) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes( $_REQUEST['shortcode'] ) : ''; |
|
211 | - if ( ! $shortcode ) { |
|
212 | - wp_die(); |
|
213 | - } |
|
214 | - $widget_args = isset( $sd_widgets[ $shortcode ] ) ? $sd_widgets[ $shortcode ] : ''; |
|
215 | - if ( ! $widget_args ) { |
|
216 | - wp_die(); |
|
217 | - } |
|
218 | - $class_name = isset( $widget_args['class_name'] ) && $widget_args['class_name'] ? $widget_args['class_name'] : ''; |
|
219 | - if ( ! $class_name ) { |
|
220 | - wp_die(); |
|
221 | - } |
|
222 | - |
|
223 | - // invoke an instance method |
|
224 | - $widget = new $class_name; |
|
225 | - |
|
226 | - ob_start(); |
|
227 | - $widget->form( array() ); |
|
228 | - $form = ob_get_clean(); |
|
229 | - echo "<form id='$shortcode'>" . $form . "<div class=\"widget-control-save\"></div></form>"; |
|
230 | - echo "<style>" . $widget->widget_css() . "</style>"; |
|
231 | - echo "<script>" . $widget->widget_js() . "</script>"; |
|
232 | - ?> |
|
165 | + $html = ob_get_clean(); |
|
166 | + |
|
167 | + if ( wp_doing_ajax() ) { |
|
168 | + echo $html; |
|
169 | + $should_die = true; |
|
170 | + |
|
171 | + // some builder get the editor via ajax so we should not die on those ocasions |
|
172 | + $dont_die = array( |
|
173 | + 'parent_tag',// WP Bakery |
|
174 | + 'avia_request' // enfold |
|
175 | + ); |
|
176 | + |
|
177 | + foreach ( $dont_die as $request ) { |
|
178 | + if ( isset( $_REQUEST[ $request ] ) ) { |
|
179 | + $should_die = false; |
|
180 | + } |
|
181 | + } |
|
182 | + |
|
183 | + if ( $should_die ) { |
|
184 | + wp_die(); |
|
185 | + } |
|
186 | + |
|
187 | + } else { |
|
188 | + return $html; |
|
189 | + } |
|
190 | + |
|
191 | + return ''; |
|
192 | + |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * Output the version in the admin header. |
|
197 | + */ |
|
198 | + public function generator() { |
|
199 | + echo '<meta name="generator" content="WP Super Duper v' . $this->version . '" />'; |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * Get widget settings. |
|
204 | + * |
|
205 | + * @since 1.0.0 |
|
206 | + */ |
|
207 | + public static function get_widget_settings() { |
|
208 | + global $sd_widgets; |
|
209 | + |
|
210 | + $shortcode = isset( $_REQUEST['shortcode'] ) && $_REQUEST['shortcode'] ? sanitize_title_with_dashes( $_REQUEST['shortcode'] ) : ''; |
|
211 | + if ( ! $shortcode ) { |
|
212 | + wp_die(); |
|
213 | + } |
|
214 | + $widget_args = isset( $sd_widgets[ $shortcode ] ) ? $sd_widgets[ $shortcode ] : ''; |
|
215 | + if ( ! $widget_args ) { |
|
216 | + wp_die(); |
|
217 | + } |
|
218 | + $class_name = isset( $widget_args['class_name'] ) && $widget_args['class_name'] ? $widget_args['class_name'] : ''; |
|
219 | + if ( ! $class_name ) { |
|
220 | + wp_die(); |
|
221 | + } |
|
222 | + |
|
223 | + // invoke an instance method |
|
224 | + $widget = new $class_name; |
|
225 | + |
|
226 | + ob_start(); |
|
227 | + $widget->form( array() ); |
|
228 | + $form = ob_get_clean(); |
|
229 | + echo "<form id='$shortcode'>" . $form . "<div class=\"widget-control-save\"></div></form>"; |
|
230 | + echo "<style>" . $widget->widget_css() . "</style>"; |
|
231 | + echo "<script>" . $widget->widget_js() . "</script>"; |
|
232 | + ?> |
|
233 | 233 | <?php |
234 | - wp_die(); |
|
235 | - } |
|
236 | - |
|
237 | - /** |
|
238 | - * Insert shortcode builder button to classic editor (not inside Gutenberg, not needed). |
|
239 | - * |
|
240 | - * @since 1.0.0 |
|
241 | - * |
|
242 | - * @param string $editor_id Optional. Shortcode editor id. Default null. |
|
243 | - * @param string $insert_shortcode_function Optional. Insert shotcode function. Default null. |
|
244 | - */ |
|
245 | - public static function shortcode_insert_button( $editor_id = '', $insert_shortcode_function = '' ) { |
|
246 | - global $sd_widgets, $shortcode_insert_button_once; |
|
247 | - if ( $shortcode_insert_button_once ) { |
|
248 | - return; |
|
249 | - } |
|
250 | - add_thickbox(); |
|
251 | - |
|
252 | - |
|
253 | - /** |
|
254 | - * Cornerstone makes us play dirty tricks :/ |
|
255 | - * All media_buttons are removed via JS unless they are two specific id's so we wrap our content in this ID so it is not removed. |
|
256 | - */ |
|
257 | - if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
258 | - echo '<span id="insert-media-button">'; |
|
259 | - } |
|
260 | - |
|
261 | - echo self::shortcode_button( 'this', 'true' ); |
|
262 | - |
|
263 | - // see opening note |
|
264 | - if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
265 | - echo '</span>'; // end #insert-media-button |
|
266 | - } |
|
267 | - |
|
268 | - self::shortcode_insert_button_script( $editor_id, $insert_shortcode_function ); |
|
269 | - $shortcode_insert_button_once = true; |
|
270 | - } |
|
271 | - |
|
272 | - /** |
|
273 | - * Gets the shortcode insert button html. |
|
274 | - * |
|
275 | - * @param string $id |
|
276 | - * @param string $search_for_id |
|
277 | - * |
|
278 | - * @return mixed |
|
279 | - */ |
|
280 | - public static function shortcode_button( $id = '', $search_for_id = '' ) { |
|
281 | - ob_start(); |
|
282 | - ?> |
|
234 | + wp_die(); |
|
235 | + } |
|
236 | + |
|
237 | + /** |
|
238 | + * Insert shortcode builder button to classic editor (not inside Gutenberg, not needed). |
|
239 | + * |
|
240 | + * @since 1.0.0 |
|
241 | + * |
|
242 | + * @param string $editor_id Optional. Shortcode editor id. Default null. |
|
243 | + * @param string $insert_shortcode_function Optional. Insert shotcode function. Default null. |
|
244 | + */ |
|
245 | + public static function shortcode_insert_button( $editor_id = '', $insert_shortcode_function = '' ) { |
|
246 | + global $sd_widgets, $shortcode_insert_button_once; |
|
247 | + if ( $shortcode_insert_button_once ) { |
|
248 | + return; |
|
249 | + } |
|
250 | + add_thickbox(); |
|
251 | + |
|
252 | + |
|
253 | + /** |
|
254 | + * Cornerstone makes us play dirty tricks :/ |
|
255 | + * All media_buttons are removed via JS unless they are two specific id's so we wrap our content in this ID so it is not removed. |
|
256 | + */ |
|
257 | + if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
258 | + echo '<span id="insert-media-button">'; |
|
259 | + } |
|
260 | + |
|
261 | + echo self::shortcode_button( 'this', 'true' ); |
|
262 | + |
|
263 | + // see opening note |
|
264 | + if ( function_exists( 'cornerstone_plugin_init' ) && ! is_admin() ) { |
|
265 | + echo '</span>'; // end #insert-media-button |
|
266 | + } |
|
267 | + |
|
268 | + self::shortcode_insert_button_script( $editor_id, $insert_shortcode_function ); |
|
269 | + $shortcode_insert_button_once = true; |
|
270 | + } |
|
271 | + |
|
272 | + /** |
|
273 | + * Gets the shortcode insert button html. |
|
274 | + * |
|
275 | + * @param string $id |
|
276 | + * @param string $search_for_id |
|
277 | + * |
|
278 | + * @return mixed |
|
279 | + */ |
|
280 | + public static function shortcode_button( $id = '', $search_for_id = '' ) { |
|
281 | + ob_start(); |
|
282 | + ?> |
|
283 | 283 | <span class="sd-lable-shortcode-inserter"> |
284 | 284 | <a onclick="sd_ajax_get_picker(<?php echo $id; |
285 | - if ( $search_for_id ) { |
|
286 | - echo "," . $search_for_id; |
|
287 | - } ?>);" href="#TB_inline?width=100%&height=550&inlineId=super-duper-content-ajaxed" |
|
285 | + if ( $search_for_id ) { |
|
286 | + echo "," . $search_for_id; |
|
287 | + } ?>);" href="#TB_inline?width=100%&height=550&inlineId=super-duper-content-ajaxed" |
|
288 | 288 | class="thickbox button super-duper-content-open" title="Add Shortcode"> |
289 | 289 | <span style="vertical-align: middle;line-height: 18px;font-size: 20px;" |
290 | 290 | class="dashicons dashicons-screenoptions"></span> |
@@ -295,21 +295,21 @@ discard block |
||
295 | 295 | </span> |
296 | 296 | |
297 | 297 | <?php |
298 | - $html = ob_get_clean(); |
|
299 | - |
|
300 | - // remove line breaks so we can use it in js |
|
301 | - return preg_replace( "/\r|\n/", "", trim( $html ) ); |
|
302 | - } |
|
303 | - |
|
304 | - /** |
|
305 | - * Makes SD work with the siteOrigin page builder. |
|
306 | - * |
|
307 | - * @since 1.0.6 |
|
308 | - * @return mixed |
|
309 | - */ |
|
310 | - public static function siteorigin_js() { |
|
311 | - ob_start(); |
|
312 | - ?> |
|
298 | + $html = ob_get_clean(); |
|
299 | + |
|
300 | + // remove line breaks so we can use it in js |
|
301 | + return preg_replace( "/\r|\n/", "", trim( $html ) ); |
|
302 | + } |
|
303 | + |
|
304 | + /** |
|
305 | + * Makes SD work with the siteOrigin page builder. |
|
306 | + * |
|
307 | + * @since 1.0.6 |
|
308 | + * @return mixed |
|
309 | + */ |
|
310 | + public static function siteorigin_js() { |
|
311 | + ob_start(); |
|
312 | + ?> |
|
313 | 313 | <script> |
314 | 314 | /** |
315 | 315 | * Check a form to see what items shoudl be shown or hidden. |
@@ -387,28 +387,28 @@ discard block |
||
387 | 387 | }); |
388 | 388 | </script> |
389 | 389 | <?php |
390 | - $output = ob_get_clean(); |
|
390 | + $output = ob_get_clean(); |
|
391 | 391 | |
392 | - /* |
|
392 | + /* |
|
393 | 393 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
394 | 394 | */ |
395 | 395 | |
396 | - return str_replace( array( |
|
397 | - '<script>', |
|
398 | - '</script>' |
|
399 | - ), '', $output ); |
|
400 | - } |
|
401 | - |
|
402 | - /** |
|
403 | - * Output the JS and CSS for the shortcode insert button. |
|
404 | - * |
|
405 | - * @since 1.0.6 |
|
406 | - * |
|
407 | - * @param string $editor_id |
|
408 | - * @param string $insert_shortcode_function |
|
409 | - */ |
|
410 | - public static function shortcode_insert_button_script( $editor_id = '', $insert_shortcode_function = '' ) { |
|
411 | - ?> |
|
396 | + return str_replace( array( |
|
397 | + '<script>', |
|
398 | + '</script>' |
|
399 | + ), '', $output ); |
|
400 | + } |
|
401 | + |
|
402 | + /** |
|
403 | + * Output the JS and CSS for the shortcode insert button. |
|
404 | + * |
|
405 | + * @since 1.0.6 |
|
406 | + * |
|
407 | + * @param string $editor_id |
|
408 | + * @param string $insert_shortcode_function |
|
409 | + */ |
|
410 | + public static function shortcode_insert_button_script( $editor_id = '', $insert_shortcode_function = '' ) { |
|
411 | + ?> |
|
412 | 412 | <style> |
413 | 413 | .sd-shortcode-left-wrap { |
414 | 414 | float: left; |
@@ -527,22 +527,22 @@ discard block |
||
527 | 527 | } |
528 | 528 | </style> |
529 | 529 | <?php |
530 | - if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
531 | - echo "<script>" . self::siteorigin_js() . "</script>"; |
|
532 | - } |
|
533 | - ?> |
|
530 | + if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
531 | + echo "<script>" . self::siteorigin_js() . "</script>"; |
|
532 | + } |
|
533 | + ?> |
|
534 | 534 | <script> |
535 | 535 | <?php |
536 | - if(! empty( $insert_shortcode_function )){ |
|
537 | - echo $insert_shortcode_function; |
|
538 | - }else{ |
|
539 | - |
|
540 | - /** |
|
541 | - * Function for super duper insert shortcode. |
|
542 | - * |
|
543 | - * @since 1.0.0 |
|
544 | - */ |
|
545 | - ?> |
|
536 | + if(! empty( $insert_shortcode_function )){ |
|
537 | + echo $insert_shortcode_function; |
|
538 | + }else{ |
|
539 | + |
|
540 | + /** |
|
541 | + * Function for super duper insert shortcode. |
|
542 | + * |
|
543 | + * @since 1.0.0 |
|
544 | + */ |
|
545 | + ?> |
|
546 | 546 | function sd_insert_shortcode($editor_id) { |
547 | 547 | $shortcode = jQuery('#TB_ajaxContent #sd-shortcode-output').val(); |
548 | 548 | if ($shortcode) { |
@@ -550,14 +550,14 @@ discard block |
||
550 | 550 | if (!$editor_id) { |
551 | 551 | |
552 | 552 | <?php |
553 | - if ( isset( $_REQUEST['et_fb'] ) ) { |
|
554 | - echo '$editor_id = "#main_content_content_vb_tiny_mce";'; |
|
555 | - } elseif ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) { |
|
556 | - echo '$editor_id = "#elementor-controls .wp-editor-container textarea";'; |
|
557 | - } else { |
|
558 | - echo '$editor_id = "#wp-content-editor-container textarea";'; |
|
559 | - } |
|
560 | - ?> |
|
553 | + if ( isset( $_REQUEST['et_fb'] ) ) { |
|
554 | + echo '$editor_id = "#main_content_content_vb_tiny_mce";'; |
|
555 | + } elseif ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) { |
|
556 | + echo '$editor_id = "#elementor-controls .wp-editor-container textarea";'; |
|
557 | + } else { |
|
558 | + echo '$editor_id = "#wp-content-editor-container textarea";'; |
|
559 | + } |
|
560 | + ?> |
|
561 | 561 | } else { |
562 | 562 | $editor_id = '#' + $editor_id; |
563 | 563 | } |
@@ -867,16 +867,16 @@ discard block |
||
867 | 867 | |
868 | 868 | </script> |
869 | 869 | <?php |
870 | - } |
|
871 | - |
|
872 | - /** |
|
873 | - * Gets some CSS for the widgets screen. |
|
874 | - * |
|
875 | - * @return mixed |
|
876 | - */ |
|
877 | - public function widget_css() { |
|
878 | - ob_start(); |
|
879 | - ?> |
|
870 | + } |
|
871 | + |
|
872 | + /** |
|
873 | + * Gets some CSS for the widgets screen. |
|
874 | + * |
|
875 | + * @return mixed |
|
876 | + */ |
|
877 | + public function widget_css() { |
|
878 | + ob_start(); |
|
879 | + ?> |
|
880 | 880 | <style> |
881 | 881 | .sd-advanced-setting { |
882 | 882 | display: none; |
@@ -897,26 +897,26 @@ discard block |
||
897 | 897 | } |
898 | 898 | </style> |
899 | 899 | <?php |
900 | - $output = ob_get_clean(); |
|
900 | + $output = ob_get_clean(); |
|
901 | 901 | |
902 | - /* |
|
902 | + /* |
|
903 | 903 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
904 | 904 | */ |
905 | 905 | |
906 | - return str_replace( array( |
|
907 | - '<style>', |
|
908 | - '</style>' |
|
909 | - ), '', $output ); |
|
910 | - } |
|
911 | - |
|
912 | - /** |
|
913 | - * Gets some JS for the widgets screen. |
|
914 | - * |
|
915 | - * @return mixed |
|
916 | - */ |
|
917 | - public function widget_js() { |
|
918 | - ob_start(); |
|
919 | - ?> |
|
906 | + return str_replace( array( |
|
907 | + '<style>', |
|
908 | + '</style>' |
|
909 | + ), '', $output ); |
|
910 | + } |
|
911 | + |
|
912 | + /** |
|
913 | + * Gets some JS for the widgets screen. |
|
914 | + * |
|
915 | + * @return mixed |
|
916 | + */ |
|
917 | + public function widget_js() { |
|
918 | + ob_start(); |
|
919 | + ?> |
|
920 | 920 | <script> |
921 | 921 | |
922 | 922 | /** |
@@ -1071,302 +1071,302 @@ discard block |
||
1071 | 1071 | <?php do_action( 'wp_super_duper_widget_js', $this ); ?> |
1072 | 1072 | </script> |
1073 | 1073 | <?php |
1074 | - $output = ob_get_clean(); |
|
1074 | + $output = ob_get_clean(); |
|
1075 | 1075 | |
1076 | - /* |
|
1076 | + /* |
|
1077 | 1077 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
1078 | 1078 | */ |
1079 | 1079 | |
1080 | - return str_replace( array( |
|
1081 | - '<script>', |
|
1082 | - '</script>' |
|
1083 | - ), '', $output ); |
|
1084 | - } |
|
1085 | - |
|
1086 | - |
|
1087 | - /** |
|
1088 | - * Set the name from the argument key. |
|
1089 | - * |
|
1090 | - * @param $options |
|
1091 | - * |
|
1092 | - * @return mixed |
|
1093 | - */ |
|
1094 | - private function add_name_from_key( $options, $arguments = false ) { |
|
1095 | - if ( ! empty( $options['arguments'] ) ) { |
|
1096 | - foreach ( $options['arguments'] as $key => $val ) { |
|
1097 | - $options['arguments'][ $key ]['name'] = $key; |
|
1098 | - } |
|
1099 | - } elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) { |
|
1100 | - foreach ( $options as $key => $val ) { |
|
1101 | - $options[ $key ]['name'] = $key; |
|
1102 | - } |
|
1103 | - } |
|
1104 | - |
|
1105 | - return $options; |
|
1106 | - } |
|
1107 | - |
|
1108 | - /** |
|
1109 | - * Register the parent shortcode. |
|
1110 | - * |
|
1111 | - * @since 1.0.0 |
|
1112 | - */ |
|
1113 | - public function register_shortcode() { |
|
1114 | - add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) ); |
|
1115 | - add_action( 'wp_ajax_super_duper_output_shortcode', array( __CLASS__, 'render_shortcode' ) ); |
|
1116 | - } |
|
1117 | - |
|
1118 | - /** |
|
1119 | - * Render the shortcode via ajax so we can return it to Gutenberg. |
|
1120 | - * |
|
1121 | - * @since 1.0.0 |
|
1122 | - */ |
|
1123 | - public static function render_shortcode() { |
|
1124 | - |
|
1125 | - check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true ); |
|
1126 | - if ( ! current_user_can( 'manage_options' ) ) { |
|
1127 | - wp_die(); |
|
1128 | - } |
|
1129 | - |
|
1130 | - // we might need the $post value here so lets set it. |
|
1131 | - if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) { |
|
1132 | - $post_obj = get_post( absint( $_POST['post_id'] ) ); |
|
1133 | - if ( ! empty( $post_obj ) && empty( $post ) ) { |
|
1134 | - global $post; |
|
1135 | - $post = $post_obj; |
|
1136 | - } |
|
1137 | - } |
|
1138 | - |
|
1139 | - if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) { |
|
1140 | - $shortcode_name = sanitize_title_with_dashes( $_POST['shortcode'] ); |
|
1141 | - $attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array(); |
|
1142 | - $attributes = ''; |
|
1143 | - if ( ! empty( $attributes_array ) ) { |
|
1144 | - foreach ( $attributes_array as $key => $value ) { |
|
1145 | - $attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . wp_slash( $value ) . "' "; |
|
1146 | - } |
|
1147 | - } |
|
1148 | - |
|
1149 | - $shortcode = "[" . $shortcode_name . " " . $attributes . "]"; |
|
1150 | - |
|
1151 | - echo do_shortcode( $shortcode ); |
|
1152 | - |
|
1153 | - } |
|
1154 | - wp_die(); |
|
1155 | - } |
|
1156 | - |
|
1157 | - /** |
|
1158 | - * Output the shortcode. |
|
1159 | - * |
|
1160 | - * @param array $args |
|
1161 | - * @param string $content |
|
1162 | - * |
|
1163 | - * @return string |
|
1164 | - */ |
|
1165 | - public function shortcode_output( $args = array(), $content = '' ) { |
|
1166 | - $args = self::argument_values( $args ); |
|
1167 | - |
|
1168 | - // add extra argument so we know its a output to gutenberg |
|
1169 | - //$args |
|
1170 | - $args = $this->string_to_bool( $args ); |
|
1171 | - |
|
1172 | - |
|
1173 | - $calss = isset( $this->options['widget_ops']['classname'] ) ? esc_attr( $this->options['widget_ops']['classname'] ) : ''; |
|
1174 | - |
|
1175 | - $calss = apply_filters( 'wp_super_duper_div_classname', $calss, $args, $this ); |
|
1176 | - $calss = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this ); |
|
1177 | - |
|
1178 | - $attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this ); |
|
1179 | - $attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this ); |
|
1180 | - |
|
1181 | - $shortcode_args = array(); |
|
1182 | - $output = ''; |
|
1183 | - $no_wrap = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false; |
|
1184 | - $main_content = $this->output( $args, $shortcode_args, $content ); |
|
1185 | - if ( $main_content && ! $no_wrap ) { |
|
1186 | - // wrap the shortcode in a dive with the same class as the widget |
|
1187 | - $output .= '<div class="' . $calss . '" ' . $attrs . '>'; |
|
1188 | - if ( ! empty( $args['title'] ) ) { |
|
1189 | - // if its a shortcode and there is a title try to grab the title wrappers |
|
1190 | - $shortcode_args = array( 'before_title' => '', 'after_title' => '' ); |
|
1191 | - if ( empty( $instance ) ) { |
|
1192 | - global $wp_registered_sidebars; |
|
1193 | - if ( ! empty( $wp_registered_sidebars ) ) { |
|
1194 | - foreach ( $wp_registered_sidebars as $sidebar ) { |
|
1195 | - if ( ! empty( $sidebar['before_title'] ) ) { |
|
1196 | - $shortcode_args['before_title'] = $sidebar['before_title']; |
|
1197 | - $shortcode_args['after_title'] = $sidebar['after_title']; |
|
1198 | - break; |
|
1199 | - } |
|
1200 | - } |
|
1201 | - } |
|
1202 | - } |
|
1203 | - $output .= $this->output_title( $shortcode_args, $args ); |
|
1204 | - } |
|
1205 | - $output .= $main_content; |
|
1206 | - $output .= '</div>'; |
|
1207 | - } elseif ( $main_content && $no_wrap ) { |
|
1208 | - $output .= $main_content; |
|
1209 | - } |
|
1210 | - |
|
1211 | - // if preview show a placeholder if empty |
|
1212 | - if ( $this->is_preview() && $output == '' ) { |
|
1213 | - $output = $this->preview_placeholder_text( "[{" . $this->base_id . "}]" ); |
|
1214 | - } |
|
1215 | - |
|
1216 | - return $output; |
|
1217 | - } |
|
1218 | - |
|
1219 | - /** |
|
1220 | - * Placeholder text to show if output is empty and we are on a preview/builder page. |
|
1221 | - * |
|
1222 | - * @param string $name |
|
1223 | - * |
|
1224 | - * @return string |
|
1225 | - */ |
|
1226 | - public function preview_placeholder_text( $name = '' ) { |
|
1227 | - return "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" . sprintf( __( 'Placeholder for: %s' ), $name ) . "</div>"; |
|
1228 | - } |
|
1229 | - |
|
1230 | - /** |
|
1231 | - * Sometimes booleans values can be turned to strings, so we fix that. |
|
1232 | - * |
|
1233 | - * @param $options |
|
1234 | - * |
|
1235 | - * @return mixed |
|
1236 | - */ |
|
1237 | - public function string_to_bool( $options ) { |
|
1238 | - // convert bool strings to booleans |
|
1239 | - foreach ( $options as $key => $val ) { |
|
1240 | - if ( $val == 'false' ) { |
|
1241 | - $options[ $key ] = false; |
|
1242 | - } elseif ( $val == 'true' ) { |
|
1243 | - $options[ $key ] = true; |
|
1244 | - } |
|
1245 | - } |
|
1246 | - |
|
1247 | - return $options; |
|
1248 | - } |
|
1249 | - |
|
1250 | - /** |
|
1251 | - * Get the argument values that are also filterable. |
|
1252 | - * |
|
1253 | - * @param $instance |
|
1254 | - * |
|
1255 | - * @return array |
|
1256 | - */ |
|
1257 | - public function argument_values( $instance ) { |
|
1258 | - $argument_values = array(); |
|
1259 | - |
|
1260 | - // set widget instance |
|
1261 | - $this->instance = $instance; |
|
1262 | - |
|
1263 | - if ( empty( $this->arguments ) ) { |
|
1264 | - $this->arguments = $this->get_arguments(); |
|
1265 | - } |
|
1266 | - |
|
1267 | - if ( ! empty( $this->arguments ) ) { |
|
1268 | - foreach ( $this->arguments as $key => $args ) { |
|
1269 | - // set the input name from the key |
|
1270 | - $args['name'] = $key; |
|
1271 | - // |
|
1272 | - $argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : ''; |
|
1273 | - if ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) { |
|
1274 | - $argument_values[ $key ] = $args['default']; |
|
1275 | - } |
|
1276 | - } |
|
1277 | - } |
|
1278 | - |
|
1279 | - return $argument_values; |
|
1280 | - } |
|
1281 | - |
|
1282 | - /** |
|
1283 | - * Set arguments in super duper. |
|
1284 | - * |
|
1285 | - * @since 1.0.0 |
|
1286 | - * |
|
1287 | - * @return array Set arguments. |
|
1288 | - */ |
|
1289 | - public function set_arguments() { |
|
1290 | - return $this->arguments; |
|
1291 | - } |
|
1292 | - |
|
1293 | - /** |
|
1294 | - * Get arguments in super duper. |
|
1295 | - * |
|
1296 | - * @since 1.0.0 |
|
1297 | - * |
|
1298 | - * @return array Get arguments. |
|
1299 | - */ |
|
1300 | - public function get_arguments() { |
|
1301 | - if ( empty( $this->arguments ) ) { |
|
1302 | - $this->arguments = $this->set_arguments(); |
|
1303 | - } |
|
1304 | - |
|
1305 | - $this->arguments = apply_filters( 'wp_super_duper_arguments', $this->arguments, $this->options, $this->instance ); |
|
1306 | - $this->arguments = $this->add_name_from_key( $this->arguments, true ); |
|
1307 | - |
|
1308 | - return $this->arguments; |
|
1309 | - } |
|
1310 | - |
|
1311 | - /** |
|
1312 | - * This is the main output class for all 3 items, widget, shortcode and block, it is extended in the calling class. |
|
1313 | - * |
|
1314 | - * @param array $args |
|
1315 | - * @param array $widget_args |
|
1316 | - * @param string $content |
|
1317 | - */ |
|
1318 | - public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
1319 | - |
|
1320 | - } |
|
1321 | - |
|
1322 | - /** |
|
1323 | - * Add the dynamic block code inline when the wp-block in enqueued. |
|
1324 | - */ |
|
1325 | - public function register_block() { |
|
1326 | - wp_add_inline_script( 'wp-blocks', $this->block() ); |
|
1327 | - if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
1328 | - |
|
1329 | - wp_add_inline_script( 'wp-blocks', $this->siteorigin_js() ); |
|
1330 | - |
|
1331 | - } |
|
1332 | - } |
|
1333 | - |
|
1334 | - /** |
|
1335 | - * Check if we need to show advanced options. |
|
1336 | - * |
|
1337 | - * @return bool |
|
1338 | - */ |
|
1339 | - public function block_show_advanced() { |
|
1340 | - |
|
1341 | - $show = false; |
|
1342 | - $arguments = $this->arguments; |
|
1343 | - |
|
1344 | - if ( empty( $arguments ) ) { |
|
1345 | - $arguments = $this->get_arguments(); |
|
1346 | - } |
|
1347 | - |
|
1348 | - if ( ! empty( $arguments ) ) { |
|
1349 | - foreach ( $arguments as $argument ) { |
|
1350 | - if ( isset( $argument['advanced'] ) && $argument['advanced'] ) { |
|
1351 | - $show = true; |
|
1352 | - } |
|
1353 | - } |
|
1354 | - } |
|
1355 | - |
|
1356 | - return $show; |
|
1357 | - } |
|
1358 | - |
|
1359 | - |
|
1360 | - /** |
|
1361 | - * Output the JS for building the dynamic Guntenberg block. |
|
1362 | - * |
|
1363 | - * @since 1.0.4 Added block_wrap property which will set the block wrapping output element ie: div, span, p or empty for no wrap. |
|
1364 | - * @since 1.0.9 Save numbers as numbers and not strings. |
|
1365 | - * @return mixed |
|
1366 | - */ |
|
1367 | - public function block() { |
|
1368 | - ob_start(); |
|
1369 | - ?> |
|
1080 | + return str_replace( array( |
|
1081 | + '<script>', |
|
1082 | + '</script>' |
|
1083 | + ), '', $output ); |
|
1084 | + } |
|
1085 | + |
|
1086 | + |
|
1087 | + /** |
|
1088 | + * Set the name from the argument key. |
|
1089 | + * |
|
1090 | + * @param $options |
|
1091 | + * |
|
1092 | + * @return mixed |
|
1093 | + */ |
|
1094 | + private function add_name_from_key( $options, $arguments = false ) { |
|
1095 | + if ( ! empty( $options['arguments'] ) ) { |
|
1096 | + foreach ( $options['arguments'] as $key => $val ) { |
|
1097 | + $options['arguments'][ $key ]['name'] = $key; |
|
1098 | + } |
|
1099 | + } elseif ( $arguments && is_array( $options ) && ! empty( $options ) ) { |
|
1100 | + foreach ( $options as $key => $val ) { |
|
1101 | + $options[ $key ]['name'] = $key; |
|
1102 | + } |
|
1103 | + } |
|
1104 | + |
|
1105 | + return $options; |
|
1106 | + } |
|
1107 | + |
|
1108 | + /** |
|
1109 | + * Register the parent shortcode. |
|
1110 | + * |
|
1111 | + * @since 1.0.0 |
|
1112 | + */ |
|
1113 | + public function register_shortcode() { |
|
1114 | + add_shortcode( $this->base_id, array( $this, 'shortcode_output' ) ); |
|
1115 | + add_action( 'wp_ajax_super_duper_output_shortcode', array( __CLASS__, 'render_shortcode' ) ); |
|
1116 | + } |
|
1117 | + |
|
1118 | + /** |
|
1119 | + * Render the shortcode via ajax so we can return it to Gutenberg. |
|
1120 | + * |
|
1121 | + * @since 1.0.0 |
|
1122 | + */ |
|
1123 | + public static function render_shortcode() { |
|
1124 | + |
|
1125 | + check_ajax_referer( 'super_duper_output_shortcode', '_ajax_nonce', true ); |
|
1126 | + if ( ! current_user_can( 'manage_options' ) ) { |
|
1127 | + wp_die(); |
|
1128 | + } |
|
1129 | + |
|
1130 | + // we might need the $post value here so lets set it. |
|
1131 | + if ( isset( $_POST['post_id'] ) && $_POST['post_id'] ) { |
|
1132 | + $post_obj = get_post( absint( $_POST['post_id'] ) ); |
|
1133 | + if ( ! empty( $post_obj ) && empty( $post ) ) { |
|
1134 | + global $post; |
|
1135 | + $post = $post_obj; |
|
1136 | + } |
|
1137 | + } |
|
1138 | + |
|
1139 | + if ( isset( $_POST['shortcode'] ) && $_POST['shortcode'] ) { |
|
1140 | + $shortcode_name = sanitize_title_with_dashes( $_POST['shortcode'] ); |
|
1141 | + $attributes_array = isset( $_POST['attributes'] ) && $_POST['attributes'] ? $_POST['attributes'] : array(); |
|
1142 | + $attributes = ''; |
|
1143 | + if ( ! empty( $attributes_array ) ) { |
|
1144 | + foreach ( $attributes_array as $key => $value ) { |
|
1145 | + $attributes .= " " . sanitize_title_with_dashes( $key ) . "='" . wp_slash( $value ) . "' "; |
|
1146 | + } |
|
1147 | + } |
|
1148 | + |
|
1149 | + $shortcode = "[" . $shortcode_name . " " . $attributes . "]"; |
|
1150 | + |
|
1151 | + echo do_shortcode( $shortcode ); |
|
1152 | + |
|
1153 | + } |
|
1154 | + wp_die(); |
|
1155 | + } |
|
1156 | + |
|
1157 | + /** |
|
1158 | + * Output the shortcode. |
|
1159 | + * |
|
1160 | + * @param array $args |
|
1161 | + * @param string $content |
|
1162 | + * |
|
1163 | + * @return string |
|
1164 | + */ |
|
1165 | + public function shortcode_output( $args = array(), $content = '' ) { |
|
1166 | + $args = self::argument_values( $args ); |
|
1167 | + |
|
1168 | + // add extra argument so we know its a output to gutenberg |
|
1169 | + //$args |
|
1170 | + $args = $this->string_to_bool( $args ); |
|
1171 | + |
|
1172 | + |
|
1173 | + $calss = isset( $this->options['widget_ops']['classname'] ) ? esc_attr( $this->options['widget_ops']['classname'] ) : ''; |
|
1174 | + |
|
1175 | + $calss = apply_filters( 'wp_super_duper_div_classname', $calss, $args, $this ); |
|
1176 | + $calss = apply_filters( 'wp_super_duper_div_classname_' . $this->base_id, $calss, $args, $this ); |
|
1177 | + |
|
1178 | + $attrs = apply_filters( 'wp_super_duper_div_attrs', '', $args, $this ); |
|
1179 | + $attrs = apply_filters( 'wp_super_duper_div_attrs_' . $this->base_id, '', $args, $this ); |
|
1180 | + |
|
1181 | + $shortcode_args = array(); |
|
1182 | + $output = ''; |
|
1183 | + $no_wrap = isset( $this->options['no_wrap'] ) && $this->options['no_wrap'] ? true : false; |
|
1184 | + $main_content = $this->output( $args, $shortcode_args, $content ); |
|
1185 | + if ( $main_content && ! $no_wrap ) { |
|
1186 | + // wrap the shortcode in a dive with the same class as the widget |
|
1187 | + $output .= '<div class="' . $calss . '" ' . $attrs . '>'; |
|
1188 | + if ( ! empty( $args['title'] ) ) { |
|
1189 | + // if its a shortcode and there is a title try to grab the title wrappers |
|
1190 | + $shortcode_args = array( 'before_title' => '', 'after_title' => '' ); |
|
1191 | + if ( empty( $instance ) ) { |
|
1192 | + global $wp_registered_sidebars; |
|
1193 | + if ( ! empty( $wp_registered_sidebars ) ) { |
|
1194 | + foreach ( $wp_registered_sidebars as $sidebar ) { |
|
1195 | + if ( ! empty( $sidebar['before_title'] ) ) { |
|
1196 | + $shortcode_args['before_title'] = $sidebar['before_title']; |
|
1197 | + $shortcode_args['after_title'] = $sidebar['after_title']; |
|
1198 | + break; |
|
1199 | + } |
|
1200 | + } |
|
1201 | + } |
|
1202 | + } |
|
1203 | + $output .= $this->output_title( $shortcode_args, $args ); |
|
1204 | + } |
|
1205 | + $output .= $main_content; |
|
1206 | + $output .= '</div>'; |
|
1207 | + } elseif ( $main_content && $no_wrap ) { |
|
1208 | + $output .= $main_content; |
|
1209 | + } |
|
1210 | + |
|
1211 | + // if preview show a placeholder if empty |
|
1212 | + if ( $this->is_preview() && $output == '' ) { |
|
1213 | + $output = $this->preview_placeholder_text( "[{" . $this->base_id . "}]" ); |
|
1214 | + } |
|
1215 | + |
|
1216 | + return $output; |
|
1217 | + } |
|
1218 | + |
|
1219 | + /** |
|
1220 | + * Placeholder text to show if output is empty and we are on a preview/builder page. |
|
1221 | + * |
|
1222 | + * @param string $name |
|
1223 | + * |
|
1224 | + * @return string |
|
1225 | + */ |
|
1226 | + public function preview_placeholder_text( $name = '' ) { |
|
1227 | + return "<div style='background:#0185ba33;padding: 10px;border: 4px #ccc dashed;'>" . sprintf( __( 'Placeholder for: %s' ), $name ) . "</div>"; |
|
1228 | + } |
|
1229 | + |
|
1230 | + /** |
|
1231 | + * Sometimes booleans values can be turned to strings, so we fix that. |
|
1232 | + * |
|
1233 | + * @param $options |
|
1234 | + * |
|
1235 | + * @return mixed |
|
1236 | + */ |
|
1237 | + public function string_to_bool( $options ) { |
|
1238 | + // convert bool strings to booleans |
|
1239 | + foreach ( $options as $key => $val ) { |
|
1240 | + if ( $val == 'false' ) { |
|
1241 | + $options[ $key ] = false; |
|
1242 | + } elseif ( $val == 'true' ) { |
|
1243 | + $options[ $key ] = true; |
|
1244 | + } |
|
1245 | + } |
|
1246 | + |
|
1247 | + return $options; |
|
1248 | + } |
|
1249 | + |
|
1250 | + /** |
|
1251 | + * Get the argument values that are also filterable. |
|
1252 | + * |
|
1253 | + * @param $instance |
|
1254 | + * |
|
1255 | + * @return array |
|
1256 | + */ |
|
1257 | + public function argument_values( $instance ) { |
|
1258 | + $argument_values = array(); |
|
1259 | + |
|
1260 | + // set widget instance |
|
1261 | + $this->instance = $instance; |
|
1262 | + |
|
1263 | + if ( empty( $this->arguments ) ) { |
|
1264 | + $this->arguments = $this->get_arguments(); |
|
1265 | + } |
|
1266 | + |
|
1267 | + if ( ! empty( $this->arguments ) ) { |
|
1268 | + foreach ( $this->arguments as $key => $args ) { |
|
1269 | + // set the input name from the key |
|
1270 | + $args['name'] = $key; |
|
1271 | + // |
|
1272 | + $argument_values[ $key ] = isset( $instance[ $key ] ) ? $instance[ $key ] : ''; |
|
1273 | + if ( $argument_values[ $key ] == '' && isset( $args['default'] ) ) { |
|
1274 | + $argument_values[ $key ] = $args['default']; |
|
1275 | + } |
|
1276 | + } |
|
1277 | + } |
|
1278 | + |
|
1279 | + return $argument_values; |
|
1280 | + } |
|
1281 | + |
|
1282 | + /** |
|
1283 | + * Set arguments in super duper. |
|
1284 | + * |
|
1285 | + * @since 1.0.0 |
|
1286 | + * |
|
1287 | + * @return array Set arguments. |
|
1288 | + */ |
|
1289 | + public function set_arguments() { |
|
1290 | + return $this->arguments; |
|
1291 | + } |
|
1292 | + |
|
1293 | + /** |
|
1294 | + * Get arguments in super duper. |
|
1295 | + * |
|
1296 | + * @since 1.0.0 |
|
1297 | + * |
|
1298 | + * @return array Get arguments. |
|
1299 | + */ |
|
1300 | + public function get_arguments() { |
|
1301 | + if ( empty( $this->arguments ) ) { |
|
1302 | + $this->arguments = $this->set_arguments(); |
|
1303 | + } |
|
1304 | + |
|
1305 | + $this->arguments = apply_filters( 'wp_super_duper_arguments', $this->arguments, $this->options, $this->instance ); |
|
1306 | + $this->arguments = $this->add_name_from_key( $this->arguments, true ); |
|
1307 | + |
|
1308 | + return $this->arguments; |
|
1309 | + } |
|
1310 | + |
|
1311 | + /** |
|
1312 | + * This is the main output class for all 3 items, widget, shortcode and block, it is extended in the calling class. |
|
1313 | + * |
|
1314 | + * @param array $args |
|
1315 | + * @param array $widget_args |
|
1316 | + * @param string $content |
|
1317 | + */ |
|
1318 | + public function output( $args = array(), $widget_args = array(), $content = '' ) { |
|
1319 | + |
|
1320 | + } |
|
1321 | + |
|
1322 | + /** |
|
1323 | + * Add the dynamic block code inline when the wp-block in enqueued. |
|
1324 | + */ |
|
1325 | + public function register_block() { |
|
1326 | + wp_add_inline_script( 'wp-blocks', $this->block() ); |
|
1327 | + if ( class_exists( 'SiteOrigin_Panels' ) ) { |
|
1328 | + |
|
1329 | + wp_add_inline_script( 'wp-blocks', $this->siteorigin_js() ); |
|
1330 | + |
|
1331 | + } |
|
1332 | + } |
|
1333 | + |
|
1334 | + /** |
|
1335 | + * Check if we need to show advanced options. |
|
1336 | + * |
|
1337 | + * @return bool |
|
1338 | + */ |
|
1339 | + public function block_show_advanced() { |
|
1340 | + |
|
1341 | + $show = false; |
|
1342 | + $arguments = $this->arguments; |
|
1343 | + |
|
1344 | + if ( empty( $arguments ) ) { |
|
1345 | + $arguments = $this->get_arguments(); |
|
1346 | + } |
|
1347 | + |
|
1348 | + if ( ! empty( $arguments ) ) { |
|
1349 | + foreach ( $arguments as $argument ) { |
|
1350 | + if ( isset( $argument['advanced'] ) && $argument['advanced'] ) { |
|
1351 | + $show = true; |
|
1352 | + } |
|
1353 | + } |
|
1354 | + } |
|
1355 | + |
|
1356 | + return $show; |
|
1357 | + } |
|
1358 | + |
|
1359 | + |
|
1360 | + /** |
|
1361 | + * Output the JS for building the dynamic Guntenberg block. |
|
1362 | + * |
|
1363 | + * @since 1.0.4 Added block_wrap property which will set the block wrapping output element ie: div, span, p or empty for no wrap. |
|
1364 | + * @since 1.0.9 Save numbers as numbers and not strings. |
|
1365 | + * @return mixed |
|
1366 | + */ |
|
1367 | + public function block() { |
|
1368 | + ob_start(); |
|
1369 | + ?> |
|
1370 | 1370 | <script> |
1371 | 1371 | /** |
1372 | 1372 | * BLOCK: Basic |
@@ -1405,76 +1405,76 @@ discard block |
||
1405 | 1405 | 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/. |
1406 | 1406 | 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. |
1407 | 1407 | <?php if ( isset( $this->options['block-keywords'] ) ) { |
1408 | - echo "keywords : " . $this->options['block-keywords'] . ","; |
|
1409 | - }?> |
|
1408 | + echo "keywords : " . $this->options['block-keywords'] . ","; |
|
1409 | + }?> |
|
1410 | 1410 | |
1411 | 1411 | <?php |
1412 | 1412 | |
1413 | - $show_advanced = $this->block_show_advanced(); |
|
1414 | - |
|
1415 | - $show_alignment = false; |
|
1416 | - |
|
1417 | - if ( ! empty( $this->arguments ) ) { |
|
1418 | - echo "attributes : {"; |
|
1419 | - |
|
1420 | - if ( $show_advanced ) { |
|
1421 | - echo "show_advanced: {"; |
|
1422 | - echo " type: 'boolean',"; |
|
1423 | - echo " default: false,"; |
|
1424 | - echo "},"; |
|
1425 | - } |
|
1426 | - |
|
1427 | - // block wrap element |
|
1428 | - if ( isset( $this->options['block-wrap'] ) ) { //@todo we should validate this? |
|
1429 | - echo "block_wrap: {"; |
|
1430 | - echo " type: 'string',"; |
|
1431 | - echo " default: '" . esc_attr( $this->options['block-wrap'] ) . "',"; |
|
1432 | - echo "},"; |
|
1433 | - } |
|
1434 | - |
|
1435 | - |
|
1436 | - foreach ( $this->arguments as $key => $args ) { |
|
1437 | - |
|
1438 | - // set if we should show alignment |
|
1439 | - if ( $key == 'alignment' ) { |
|
1440 | - $show_alignment = true; |
|
1441 | - } |
|
1442 | - |
|
1443 | - $extra = ''; |
|
1444 | - |
|
1445 | - if ( $args['type'] == 'checkbox' ) { |
|
1446 | - $type = 'boolean'; |
|
1447 | - $default = isset( $args['default'] ) && $args['default'] ? 'true' : 'false'; |
|
1448 | - } elseif ( $args['type'] == 'number' ) { |
|
1449 | - $type = 'number'; |
|
1450 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
1451 | - } elseif ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) { |
|
1452 | - $type = 'array'; |
|
1453 | - if ( is_array( $args['default'] ) ) { |
|
1454 | - $default = isset( $args['default'] ) ? "['" . implode( "','", $args['default'] ) . "']" : "[]"; |
|
1455 | - } else { |
|
1456 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
1457 | - } |
|
1458 | - } elseif ( $args['type'] == 'multiselect' ) { |
|
1459 | - $type = 'array'; |
|
1460 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
1461 | - } else { |
|
1462 | - $type = 'string'; |
|
1463 | - $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
1464 | - } |
|
1465 | - echo $key . " : {"; |
|
1466 | - echo "type : '$type',"; |
|
1467 | - echo "default : $default,"; |
|
1468 | - echo "},"; |
|
1469 | - } |
|
1470 | - |
|
1471 | - echo "content : {type : 'string',default: 'Please select the attributes in the block settings'},"; |
|
1472 | - |
|
1473 | - echo "},"; |
|
1474 | - |
|
1475 | - } |
|
1476 | - |
|
1477 | - ?> |
|
1413 | + $show_advanced = $this->block_show_advanced(); |
|
1414 | + |
|
1415 | + $show_alignment = false; |
|
1416 | + |
|
1417 | + if ( ! empty( $this->arguments ) ) { |
|
1418 | + echo "attributes : {"; |
|
1419 | + |
|
1420 | + if ( $show_advanced ) { |
|
1421 | + echo "show_advanced: {"; |
|
1422 | + echo " type: 'boolean',"; |
|
1423 | + echo " default: false,"; |
|
1424 | + echo "},"; |
|
1425 | + } |
|
1426 | + |
|
1427 | + // block wrap element |
|
1428 | + if ( isset( $this->options['block-wrap'] ) ) { //@todo we should validate this? |
|
1429 | + echo "block_wrap: {"; |
|
1430 | + echo " type: 'string',"; |
|
1431 | + echo " default: '" . esc_attr( $this->options['block-wrap'] ) . "',"; |
|
1432 | + echo "},"; |
|
1433 | + } |
|
1434 | + |
|
1435 | + |
|
1436 | + foreach ( $this->arguments as $key => $args ) { |
|
1437 | + |
|
1438 | + // set if we should show alignment |
|
1439 | + if ( $key == 'alignment' ) { |
|
1440 | + $show_alignment = true; |
|
1441 | + } |
|
1442 | + |
|
1443 | + $extra = ''; |
|
1444 | + |
|
1445 | + if ( $args['type'] == 'checkbox' ) { |
|
1446 | + $type = 'boolean'; |
|
1447 | + $default = isset( $args['default'] ) && $args['default'] ? 'true' : 'false'; |
|
1448 | + } elseif ( $args['type'] == 'number' ) { |
|
1449 | + $type = 'number'; |
|
1450 | + $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
1451 | + } elseif ( $args['type'] == 'select' && ! empty( $args['multiple'] ) ) { |
|
1452 | + $type = 'array'; |
|
1453 | + if ( is_array( $args['default'] ) ) { |
|
1454 | + $default = isset( $args['default'] ) ? "['" . implode( "','", $args['default'] ) . "']" : "[]"; |
|
1455 | + } else { |
|
1456 | + $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
1457 | + } |
|
1458 | + } elseif ( $args['type'] == 'multiselect' ) { |
|
1459 | + $type = 'array'; |
|
1460 | + $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
1461 | + } else { |
|
1462 | + $type = 'string'; |
|
1463 | + $default = isset( $args['default'] ) ? "'" . $args['default'] . "'" : "''"; |
|
1464 | + } |
|
1465 | + echo $key . " : {"; |
|
1466 | + echo "type : '$type',"; |
|
1467 | + echo "default : $default,"; |
|
1468 | + echo "},"; |
|
1469 | + } |
|
1470 | + |
|
1471 | + echo "content : {type : 'string',default: 'Please select the attributes in the block settings'},"; |
|
1472 | + |
|
1473 | + echo "},"; |
|
1474 | + |
|
1475 | + } |
|
1476 | + |
|
1477 | + ?> |
|
1478 | 1478 | |
1479 | 1479 | // The "edit" property must be a valid function. |
1480 | 1480 | edit: function (props) { |
@@ -1493,8 +1493,8 @@ discard block |
||
1493 | 1493 | 'shortcode': '<?php echo $this->options['base_id'];?>', |
1494 | 1494 | 'attributes': props.attributes, |
1495 | 1495 | 'post_id': <?php global $post; if ( isset( $post->ID ) ) { |
1496 | - echo $post->ID; |
|
1497 | - }?>, |
|
1496 | + echo $post->ID; |
|
1497 | + }?>, |
|
1498 | 1498 | '_ajax_nonce': '<?php echo wp_create_nonce( 'super_duper_output_shortcode' );?>' |
1499 | 1499 | }; |
1500 | 1500 | |
@@ -1541,10 +1541,10 @@ discard block |
||
1541 | 1541 | |
1542 | 1542 | <?php |
1543 | 1543 | |
1544 | - if(! empty( $this->arguments )){ |
|
1544 | + if(! empty( $this->arguments )){ |
|
1545 | 1545 | |
1546 | - if ( $show_advanced ) { |
|
1547 | - ?> |
|
1546 | + if ( $show_advanced ) { |
|
1547 | + ?> |
|
1548 | 1548 | el( |
1549 | 1549 | wp.components.ToggleControl, |
1550 | 1550 | { |
@@ -1557,73 +1557,73 @@ discard block |
||
1557 | 1557 | ), |
1558 | 1558 | <?php |
1559 | 1559 | |
1560 | - } |
|
1561 | - |
|
1562 | - foreach($this->arguments as $key => $args){ |
|
1563 | - $custom_attributes = ! empty( $args['custom_attributes'] ) ? $this->array_to_attributes( $args['custom_attributes'] ) : ''; |
|
1564 | - $options = ''; |
|
1565 | - $extra = ''; |
|
1566 | - $require = ''; |
|
1567 | - $onchange = "props.setAttributes({ $key: $key } )"; |
|
1568 | - $value = "props.attributes.$key"; |
|
1569 | - $text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'color' ); |
|
1570 | - if ( in_array( $args['type'], $text_type ) ) { |
|
1571 | - $type = 'TextControl'; |
|
1572 | - // Save numbers as numbers and not strings |
|
1573 | - if ( $args['type'] == 'number' ) { |
|
1574 | - $onchange = "props.setAttributes({ $key: Number($key) } )"; |
|
1575 | - } |
|
1576 | - } |
|
1560 | + } |
|
1561 | + |
|
1562 | + foreach($this->arguments as $key => $args){ |
|
1563 | + $custom_attributes = ! empty( $args['custom_attributes'] ) ? $this->array_to_attributes( $args['custom_attributes'] ) : ''; |
|
1564 | + $options = ''; |
|
1565 | + $extra = ''; |
|
1566 | + $require = ''; |
|
1567 | + $onchange = "props.setAttributes({ $key: $key } )"; |
|
1568 | + $value = "props.attributes.$key"; |
|
1569 | + $text_type = array( 'text', 'password', 'number', 'email', 'tel', 'url', 'color' ); |
|
1570 | + if ( in_array( $args['type'], $text_type ) ) { |
|
1571 | + $type = 'TextControl'; |
|
1572 | + // Save numbers as numbers and not strings |
|
1573 | + if ( $args['type'] == 'number' ) { |
|
1574 | + $onchange = "props.setAttributes({ $key: Number($key) } )"; |
|
1575 | + } |
|
1576 | + } |
|
1577 | 1577 | // elseif ( $args['type'] == 'color' ) { //@todo ColorPicker labels are not shown yet, we may have to add our own https://github.com/WordPress/gutenberg/issues/14378 |
1578 | 1578 | // $type = 'ColorPicker'; |
1579 | 1579 | // } |
1580 | - elseif ( $args['type'] == 'checkbox' ) { |
|
1581 | - $type = 'CheckboxControl'; |
|
1582 | - $extra .= "checked: props.attributes.$key,"; |
|
1583 | - $onchange = "props.setAttributes({ $key: ! props.attributes.$key } )"; |
|
1584 | - } elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) { |
|
1585 | - $type = 'SelectControl'; |
|
1586 | - if ( ! empty( $args['options'] ) ) { |
|
1587 | - $options .= "options : ["; |
|
1588 | - foreach ( $args['options'] as $option_val => $option_label ) { |
|
1589 | - $options .= "{ value : '" . esc_attr( $option_val ) . "', label : '" . esc_attr( $option_label ) . "' },"; |
|
1590 | - } |
|
1591 | - $options .= "],"; |
|
1592 | - } |
|
1593 | - if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550 |
|
1594 | - $extra .= ' multiple: true, '; |
|
1595 | - //$onchange = "props.setAttributes({ $key: ['edit'] } )"; |
|
1596 | - //$value = "['edit', 'delete']"; |
|
1597 | - } |
|
1598 | - } elseif ( $args['type'] == 'alignment' ) { |
|
1599 | - $type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example |
|
1600 | - } else { |
|
1601 | - continue;// if we have not implemented the control then don't break the JS. |
|
1602 | - } |
|
1603 | - |
|
1604 | - // add show only if advanced |
|
1605 | - if ( ! empty( $args['advanced'] ) ) { |
|
1606 | - echo "props.attributes.show_advanced && "; |
|
1607 | - } |
|
1608 | - // add setting require if defined |
|
1609 | - if ( ! empty( $args['element_require'] ) ) { |
|
1610 | - echo $this->block_props_replace( $args['element_require'], true ) . " && "; |
|
1611 | - } |
|
1612 | - ?> |
|
1580 | + elseif ( $args['type'] == 'checkbox' ) { |
|
1581 | + $type = 'CheckboxControl'; |
|
1582 | + $extra .= "checked: props.attributes.$key,"; |
|
1583 | + $onchange = "props.setAttributes({ $key: ! props.attributes.$key } )"; |
|
1584 | + } elseif ( $args['type'] == 'select' || $args['type'] == 'multiselect' ) { |
|
1585 | + $type = 'SelectControl'; |
|
1586 | + if ( ! empty( $args['options'] ) ) { |
|
1587 | + $options .= "options : ["; |
|
1588 | + foreach ( $args['options'] as $option_val => $option_label ) { |
|
1589 | + $options .= "{ value : '" . esc_attr( $option_val ) . "', label : '" . esc_attr( $option_label ) . "' },"; |
|
1590 | + } |
|
1591 | + $options .= "],"; |
|
1592 | + } |
|
1593 | + if ( isset( $args['multiple'] ) && $args['multiple'] ) { //@todo multiselect does not work at the moment: https://github.com/WordPress/gutenberg/issues/5550 |
|
1594 | + $extra .= ' multiple: true, '; |
|
1595 | + //$onchange = "props.setAttributes({ $key: ['edit'] } )"; |
|
1596 | + //$value = "['edit', 'delete']"; |
|
1597 | + } |
|
1598 | + } elseif ( $args['type'] == 'alignment' ) { |
|
1599 | + $type = 'AlignmentToolbar'; // @todo this does not seem to work but cant find a example |
|
1600 | + } else { |
|
1601 | + continue;// if we have not implemented the control then don't break the JS. |
|
1602 | + } |
|
1603 | + |
|
1604 | + // add show only if advanced |
|
1605 | + if ( ! empty( $args['advanced'] ) ) { |
|
1606 | + echo "props.attributes.show_advanced && "; |
|
1607 | + } |
|
1608 | + // add setting require if defined |
|
1609 | + if ( ! empty( $args['element_require'] ) ) { |
|
1610 | + echo $this->block_props_replace( $args['element_require'], true ) . " && "; |
|
1611 | + } |
|
1612 | + ?> |
|
1613 | 1613 | el( |
1614 | 1614 | wp.components.<?php echo esc_attr( $type );?>, |
1615 | 1615 | { |
1616 | 1616 | label: '<?php echo esc_attr( $args['title'] );?>', |
1617 | 1617 | help: '<?php if ( isset( $args['desc'] ) ) { |
1618 | - echo esc_attr( $args['desc'] ); |
|
1619 | - }?>', |
|
1618 | + echo esc_attr( $args['desc'] ); |
|
1619 | + }?>', |
|
1620 | 1620 | value: <?php echo $value;?>, |
1621 | 1621 | <?php if ( $type == 'TextControl' && $args['type'] != 'text' ) { |
1622 | - echo "type: '" . esc_attr( $args['type'] ) . "',"; |
|
1623 | - }?> |
|
1622 | + echo "type: '" . esc_attr( $args['type'] ) . "',"; |
|
1623 | + }?> |
|
1624 | 1624 | <?php if ( ! empty( $args['placeholder'] ) ) { |
1625 | - echo "placeholder: '" . esc_attr( $args['placeholder'] ) . "',"; |
|
1626 | - }?> |
|
1625 | + echo "placeholder: '" . esc_attr( $args['placeholder'] ) . "',"; |
|
1626 | + }?> |
|
1627 | 1627 | <?php echo $options;?> |
1628 | 1628 | <?php echo $extra;?> |
1629 | 1629 | <?php echo $custom_attributes;?> |
@@ -1633,27 +1633,27 @@ discard block |
||
1633 | 1633 | } |
1634 | 1634 | ), |
1635 | 1635 | <?php |
1636 | - } |
|
1637 | - } |
|
1638 | - ?> |
|
1636 | + } |
|
1637 | + } |
|
1638 | + ?> |
|
1639 | 1639 | |
1640 | 1640 | ), |
1641 | 1641 | |
1642 | 1642 | <?php |
1643 | - // If the user sets block-output array then build it |
|
1644 | - if ( ! empty( $this->options['block-output'] ) ) { |
|
1645 | - $this->block_element( $this->options['block-output'] ); |
|
1646 | - }else{ |
|
1647 | - // if no block-output is set then we try and get the shortcode html output via ajax. |
|
1648 | - ?> |
|
1643 | + // If the user sets block-output array then build it |
|
1644 | + if ( ! empty( $this->options['block-output'] ) ) { |
|
1645 | + $this->block_element( $this->options['block-output'] ); |
|
1646 | + }else{ |
|
1647 | + // if no block-output is set then we try and get the shortcode html output via ajax. |
|
1648 | + ?> |
|
1649 | 1649 | el('div', { |
1650 | 1650 | dangerouslySetInnerHTML: {__html: onChangeContent()}, |
1651 | 1651 | className: props.className, |
1652 | 1652 | style: {'min-height': '30px'} |
1653 | 1653 | }) |
1654 | 1654 | <?php |
1655 | - } |
|
1656 | - ?> |
|
1655 | + } |
|
1656 | + ?> |
|
1657 | 1657 | ]; // end return |
1658 | 1658 | }, |
1659 | 1659 | |
@@ -1670,17 +1670,17 @@ discard block |
||
1670 | 1670 | var content = "[<?php echo $this->options['base_id'];?>"; |
1671 | 1671 | <?php |
1672 | 1672 | |
1673 | - if(! empty( $this->arguments )){ |
|
1674 | - foreach($this->arguments as $key => $args){ |
|
1675 | - ?> |
|
1673 | + if(! empty( $this->arguments )){ |
|
1674 | + foreach($this->arguments as $key => $args){ |
|
1675 | + ?> |
|
1676 | 1676 | if (attr.hasOwnProperty("<?php echo esc_attr( $key );?>")) { |
1677 | 1677 | content += " <?php echo esc_attr( $key );?>='" + attr.<?php echo esc_attr( $key );?>+ "' "; |
1678 | 1678 | } |
1679 | 1679 | <?php |
1680 | - } |
|
1681 | - } |
|
1680 | + } |
|
1681 | + } |
|
1682 | 1682 | |
1683 | - ?> |
|
1683 | + ?> |
|
1684 | 1684 | content += "]"; |
1685 | 1685 | |
1686 | 1686 | |
@@ -1709,456 +1709,456 @@ discard block |
||
1709 | 1709 | })(); |
1710 | 1710 | </script> |
1711 | 1711 | <?php |
1712 | - $output = ob_get_clean(); |
|
1712 | + $output = ob_get_clean(); |
|
1713 | 1713 | |
1714 | - /* |
|
1714 | + /* |
|
1715 | 1715 | * We only add the <script> tags for code highlighting, so we strip them from the output. |
1716 | 1716 | */ |
1717 | 1717 | |
1718 | - return str_replace( array( |
|
1719 | - '<script>', |
|
1720 | - '</script>' |
|
1721 | - ), '', $output ); |
|
1722 | - } |
|
1723 | - |
|
1724 | - /** |
|
1725 | - * Convert an array of attributes to block string. |
|
1726 | - * |
|
1727 | - * @todo there is prob a faster way to do this, also we could add some validation here. |
|
1728 | - * |
|
1729 | - * @param $custom_attributes |
|
1730 | - * |
|
1731 | - * @return string |
|
1732 | - */ |
|
1733 | - public function array_to_attributes( $custom_attributes, $html = false ) { |
|
1734 | - $attributes = ''; |
|
1735 | - if ( ! empty( $custom_attributes ) ) { |
|
1736 | - |
|
1737 | - if ( $html ) { |
|
1738 | - foreach ( $custom_attributes as $key => $val ) { |
|
1739 | - $attributes .= " $key='$val' "; |
|
1740 | - } |
|
1741 | - } else { |
|
1742 | - foreach ( $custom_attributes as $key => $val ) { |
|
1743 | - $attributes .= "'$key': '$val',"; |
|
1744 | - } |
|
1745 | - } |
|
1746 | - } |
|
1747 | - |
|
1748 | - return $attributes; |
|
1749 | - } |
|
1750 | - |
|
1751 | - /** |
|
1752 | - * A self looping function to create the output for JS block elements. |
|
1753 | - * |
|
1754 | - * This is what is output in the WP Editor visual view. |
|
1755 | - * |
|
1756 | - * @param $args |
|
1757 | - */ |
|
1758 | - public function block_element( $args ) { |
|
1759 | - |
|
1760 | - |
|
1761 | - if ( ! empty( $args ) ) { |
|
1762 | - foreach ( $args as $element => $new_args ) { |
|
1763 | - |
|
1764 | - if ( is_array( $new_args ) ) { // its an element |
|
1765 | - |
|
1766 | - |
|
1767 | - if ( isset( $new_args['element'] ) ) { |
|
1768 | - |
|
1769 | - if ( isset( $new_args['element_require'] ) ) { |
|
1770 | - echo str_replace( array( |
|
1771 | - "'+", |
|
1772 | - "+'" |
|
1773 | - ), '', $this->block_props_replace( $new_args['element_require'] ) ) . " && "; |
|
1774 | - unset( $new_args['element_require'] ); |
|
1775 | - } |
|
1776 | - |
|
1777 | - echo "\n el( '" . $new_args['element'] . "', {"; |
|
1778 | - |
|
1779 | - // get the attributes |
|
1780 | - foreach ( $new_args as $new_key => $new_value ) { |
|
1781 | - |
|
1782 | - |
|
1783 | - if ( $new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) { |
|
1784 | - // do nothing |
|
1785 | - } else { |
|
1786 | - echo $this->block_element( array( $new_key => $new_value ) ); |
|
1787 | - } |
|
1788 | - } |
|
1789 | - |
|
1790 | - echo "},";// end attributes |
|
1791 | - |
|
1792 | - // get the content |
|
1793 | - $first_item = 0; |
|
1794 | - foreach ( $new_args as $new_key => $new_value ) { |
|
1795 | - if ( $new_key === 'content' || is_array( $new_value ) ) { |
|
1796 | - |
|
1797 | - if ( $new_key === 'content' ) { |
|
1798 | - echo "'" . $this->block_props_replace( $new_value ) . "'"; |
|
1799 | - } |
|
1800 | - |
|
1801 | - if ( is_array( $new_value ) ) { |
|
1802 | - |
|
1803 | - if ( isset( $new_value['element_require'] ) ) { |
|
1804 | - echo str_replace( array( |
|
1805 | - "'+", |
|
1806 | - "+'" |
|
1807 | - ), '', $this->block_props_replace( $new_value['element_require'] ) ) . " && "; |
|
1808 | - unset( $new_value['element_require'] ); |
|
1809 | - } |
|
1810 | - |
|
1811 | - if ( isset( $new_value['element_repeat'] ) ) { |
|
1812 | - $x = 1; |
|
1813 | - while ( $x <= absint( $new_value['element_repeat'] ) ) { |
|
1814 | - $this->block_element( array( '' => $new_value ) ); |
|
1815 | - $x ++; |
|
1816 | - } |
|
1817 | - } else { |
|
1818 | - $this->block_element( array( '' => $new_value ) ); |
|
1819 | - } |
|
1820 | - } |
|
1821 | - $first_item ++; |
|
1822 | - } |
|
1823 | - } |
|
1824 | - |
|
1825 | - echo ")";// end content |
|
1826 | - |
|
1827 | - echo ", \n"; |
|
1828 | - |
|
1829 | - } |
|
1830 | - } else { |
|
1831 | - |
|
1832 | - if ( substr( $element, 0, 3 ) === "if_" ) { |
|
1833 | - echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ","; |
|
1834 | - } elseif ( $element == 'style' ) { |
|
1835 | - echo $element . ": " . $this->block_props_replace( $new_args ) . ","; |
|
1836 | - } else { |
|
1837 | - echo $element . ": '" . $this->block_props_replace( $new_args ) . "',"; |
|
1838 | - } |
|
1839 | - |
|
1840 | - } |
|
1841 | - } |
|
1842 | - } |
|
1843 | - } |
|
1844 | - |
|
1845 | - /** |
|
1846 | - * Replace block attributes placeholders with the proper naming. |
|
1847 | - * |
|
1848 | - * @param $string |
|
1849 | - * |
|
1850 | - * @return mixed |
|
1851 | - */ |
|
1852 | - public function block_props_replace( $string, $no_wrap = false ) { |
|
1853 | - |
|
1854 | - if ( $no_wrap ) { |
|
1855 | - $string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string ); |
|
1856 | - } else { |
|
1857 | - $string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string ); |
|
1858 | - } |
|
1859 | - |
|
1860 | - return $string; |
|
1861 | - } |
|
1862 | - |
|
1863 | - /** |
|
1864 | - * Outputs the content of the widget |
|
1865 | - * |
|
1866 | - * @param array $args |
|
1867 | - * @param array $instance |
|
1868 | - */ |
|
1869 | - public function widget( $args, $instance ) { |
|
1870 | - |
|
1871 | - // get the filtered values |
|
1872 | - $argument_values = $this->argument_values( $instance ); |
|
1873 | - $argument_values = $this->string_to_bool( $argument_values ); |
|
1874 | - $output = $this->output( $argument_values, $args ); |
|
1875 | - |
|
1876 | - if ( $output ) { |
|
1877 | - // Before widget |
|
1878 | - $before_widget = $args['before_widget']; |
|
1879 | - $before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this ); |
|
1880 | - $before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this ); |
|
1881 | - |
|
1882 | - // After widget |
|
1883 | - $after_widget = $args['after_widget']; |
|
1884 | - $after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this ); |
|
1885 | - $after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this ); |
|
1886 | - |
|
1887 | - echo $before_widget; |
|
1888 | - // elementor strips the widget wrapping div so we check for and add it back if needed |
|
1889 | - if ( $this->is_elementor_widget_output() ) { |
|
1890 | - echo ! empty( $this->options['widget_ops']['classname'] ) ? "<span class='" . esc_attr( $this->options['widget_ops']['classname'] ) . "'>" : ''; |
|
1891 | - } |
|
1892 | - echo $this->output_title( $args, $instance ); |
|
1893 | - echo $output; |
|
1894 | - if ( $this->is_elementor_widget_output() ) { |
|
1895 | - echo ! empty( $this->options['widget_ops']['classname'] ) ? "</span>" : ''; |
|
1896 | - } |
|
1897 | - echo $after_widget; |
|
1898 | - } elseif ( $this->is_preview() && $output == '' ) {// if preview show a placeholder if empty |
|
1899 | - $output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" ); |
|
1900 | - echo $output; |
|
1901 | - } |
|
1902 | - } |
|
1903 | - |
|
1904 | - /** |
|
1905 | - * Tests if the current output is inside a elementor container. |
|
1906 | - * |
|
1907 | - * @since 1.0.4 |
|
1908 | - * @return bool |
|
1909 | - */ |
|
1910 | - public function is_elementor_widget_output() { |
|
1911 | - $result = false; |
|
1912 | - if ( defined( 'ELEMENTOR_VERSION' ) && isset( $this->number ) && $this->number == 'REPLACE_TO_ID' ) { |
|
1913 | - $result = true; |
|
1914 | - } |
|
1915 | - |
|
1916 | - return $result; |
|
1917 | - } |
|
1918 | - |
|
1919 | - /** |
|
1920 | - * Tests if the current output is inside a elementor preview. |
|
1921 | - * |
|
1922 | - * @since 1.0.4 |
|
1923 | - * @return bool |
|
1924 | - */ |
|
1925 | - public function is_elementor_preview() { |
|
1926 | - $result = false; |
|
1927 | - if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ) { |
|
1928 | - $result = true; |
|
1929 | - } |
|
1930 | - |
|
1931 | - return $result; |
|
1932 | - } |
|
1933 | - |
|
1934 | - /** |
|
1935 | - * Tests if the current output is inside a Divi preview. |
|
1936 | - * |
|
1937 | - * @since 1.0.6 |
|
1938 | - * @return bool |
|
1939 | - */ |
|
1940 | - public function is_divi_preview() { |
|
1941 | - $result = false; |
|
1942 | - if ( isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) { |
|
1943 | - $result = true; |
|
1944 | - } |
|
1945 | - |
|
1946 | - return $result; |
|
1947 | - } |
|
1948 | - |
|
1949 | - /** |
|
1950 | - * Tests if the current output is inside a Beaver builder preview. |
|
1951 | - * |
|
1952 | - * @since 1.0.6 |
|
1953 | - * @return bool |
|
1954 | - */ |
|
1955 | - public function is_beaver_preview() { |
|
1956 | - $result = false; |
|
1957 | - if ( isset( $_REQUEST['fl_builder'] ) ) { |
|
1958 | - $result = true; |
|
1959 | - } |
|
1960 | - |
|
1961 | - return $result; |
|
1962 | - } |
|
1963 | - |
|
1964 | - /** |
|
1965 | - * Tests if the current output is inside a siteorigin builder preview. |
|
1966 | - * |
|
1967 | - * @since 1.0.6 |
|
1968 | - * @return bool |
|
1969 | - */ |
|
1970 | - public function is_siteorigin_preview() { |
|
1971 | - $result = false; |
|
1972 | - if ( ! empty( $_REQUEST['siteorigin_panels_live_editor'] ) ) { |
|
1973 | - $result = true; |
|
1974 | - } |
|
1975 | - |
|
1976 | - return $result; |
|
1977 | - } |
|
1978 | - |
|
1979 | - /** |
|
1980 | - * Tests if the current output is inside a cornerstone builder preview. |
|
1981 | - * |
|
1982 | - * @since 1.0.8 |
|
1983 | - * @return bool |
|
1984 | - */ |
|
1985 | - public function is_cornerstone_preview() { |
|
1986 | - $result = false; |
|
1987 | - if ( ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint' ) { |
|
1988 | - $result = true; |
|
1989 | - } |
|
1990 | - |
|
1991 | - return $result; |
|
1992 | - } |
|
1993 | - |
|
1994 | - /** |
|
1995 | - * General function to check if we are in a preview situation. |
|
1996 | - * |
|
1997 | - * @since 1.0.6 |
|
1998 | - * @return bool |
|
1999 | - */ |
|
2000 | - public function is_preview() { |
|
2001 | - $preview = false; |
|
2002 | - if ( $this->is_divi_preview() ) { |
|
2003 | - $preview = true; |
|
2004 | - } elseif ( $this->is_elementor_preview() ) { |
|
2005 | - $preview = true; |
|
2006 | - } elseif ( $this->is_beaver_preview() ) { |
|
2007 | - $preview = true; |
|
2008 | - } elseif ( $this->is_siteorigin_preview() ) { |
|
2009 | - $preview = true; |
|
2010 | - } elseif ( $this->is_cornerstone_preview() ) { |
|
2011 | - $preview = true; |
|
2012 | - } |
|
2013 | - |
|
2014 | - return $preview; |
|
2015 | - } |
|
2016 | - |
|
2017 | - /** |
|
2018 | - * Output the super title. |
|
2019 | - * |
|
2020 | - * @param $args |
|
2021 | - * @param array $instance |
|
2022 | - * |
|
2023 | - * @return string |
|
2024 | - */ |
|
2025 | - public function output_title( $args, $instance = array() ) { |
|
2026 | - $output = ''; |
|
2027 | - if ( ! empty( $instance['title'] ) ) { |
|
2028 | - /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
|
2029 | - $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); |
|
2030 | - $output = $args['before_title'] . $title . $args['after_title']; |
|
2031 | - } |
|
2032 | - |
|
2033 | - return $output; |
|
2034 | - } |
|
2035 | - |
|
2036 | - /** |
|
2037 | - * Outputs the options form inputs for the widget. |
|
2038 | - * |
|
2039 | - * @param array $instance The widget options. |
|
2040 | - */ |
|
2041 | - public function form( $instance ) { |
|
2042 | - |
|
2043 | - // set widget instance |
|
2044 | - $this->instance = $instance; |
|
2045 | - |
|
2046 | - // set it as a SD widget |
|
2047 | - echo $this->widget_advanced_toggle(); |
|
2048 | - |
|
2049 | - echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>"; |
|
2050 | - $arguments = $this->get_arguments(); |
|
2051 | - |
|
2052 | - if ( is_array( $arguments ) ) { |
|
2053 | - foreach ( $arguments as $key => $args ) { |
|
2054 | - $this->widget_inputs( $args, $instance ); |
|
2055 | - } |
|
2056 | - } |
|
2057 | - } |
|
2058 | - |
|
2059 | - /** |
|
2060 | - * Get the hidden input that when added makes the advanced button show on widget settings. |
|
2061 | - * |
|
2062 | - * @return string |
|
2063 | - */ |
|
2064 | - public function widget_advanced_toggle() { |
|
2065 | - |
|
2066 | - $output = ''; |
|
2067 | - if ( $this->block_show_advanced() ) { |
|
2068 | - $val = 1; |
|
2069 | - } else { |
|
2070 | - $val = 0; |
|
2071 | - } |
|
2072 | - |
|
2073 | - $output .= "<input type='hidden' class='sd-show-advanced' value='$val' />"; |
|
2074 | - |
|
2075 | - return $output; |
|
2076 | - } |
|
2077 | - |
|
2078 | - /** |
|
2079 | - * Convert require element. |
|
2080 | - * |
|
2081 | - * @since 1.0.0 |
|
2082 | - * |
|
2083 | - * @param string $input Input element. |
|
2084 | - * |
|
2085 | - * @return string $output |
|
2086 | - */ |
|
2087 | - public function convert_element_require( $input ) { |
|
2088 | - |
|
2089 | - $input = str_replace( "'", '"', $input );// we only want double quotes |
|
2090 | - |
|
2091 | - $output = esc_attr( str_replace( array( "[%", "%]" ), array( |
|
2092 | - "jQuery(form).find('[data-argument=\"", |
|
2093 | - "\"]').find('input,select').val()" |
|
2094 | - ), $input ) ); |
|
2095 | - |
|
2096 | - return $output; |
|
2097 | - } |
|
2098 | - |
|
2099 | - /** |
|
2100 | - * Builds the inputs for the widget options. |
|
2101 | - * |
|
2102 | - * @param $args |
|
2103 | - * @param $instance |
|
2104 | - */ |
|
2105 | - public function widget_inputs( $args, $instance ) { |
|
2106 | - |
|
2107 | - $class = ""; |
|
2108 | - $element_require = ""; |
|
2109 | - $custom_attributes = ""; |
|
2110 | - |
|
2111 | - // get value |
|
2112 | - if ( isset( $instance[ $args['name'] ] ) ) { |
|
2113 | - $value = $instance[ $args['name'] ]; |
|
2114 | - } elseif ( ! isset( $instance[ $args['name'] ] ) && ! empty( $args['default'] ) ) { |
|
2115 | - $value = is_array( $args['default'] ) ? array_map( "esc_html", $args['default'] ) : esc_html( $args['default'] ); |
|
2116 | - } else { |
|
2117 | - $value = ''; |
|
2118 | - } |
|
2119 | - |
|
2120 | - // get placeholder |
|
2121 | - if ( ! empty( $args['placeholder'] ) ) { |
|
2122 | - $placeholder = "placeholder='" . esc_html( $args['placeholder'] ) . "'"; |
|
2123 | - } else { |
|
2124 | - $placeholder = ''; |
|
2125 | - } |
|
2126 | - |
|
2127 | - // get if advanced |
|
2128 | - if ( isset( $args['advanced'] ) && $args['advanced'] ) { |
|
2129 | - $class .= " sd-advanced-setting "; |
|
2130 | - } |
|
2131 | - |
|
2132 | - // element_require |
|
2133 | - if ( isset( $args['element_require'] ) && $args['element_require'] ) { |
|
2134 | - $element_require = $args['element_require']; |
|
2135 | - } |
|
2136 | - |
|
2137 | - // custom_attributes |
|
2138 | - if ( isset( $args['custom_attributes'] ) && $args['custom_attributes'] ) { |
|
2139 | - $custom_attributes = $this->array_to_attributes( $args['custom_attributes'], true ); |
|
2140 | - } |
|
2141 | - |
|
2142 | - // before wrapper |
|
2143 | - ?> |
|
1718 | + return str_replace( array( |
|
1719 | + '<script>', |
|
1720 | + '</script>' |
|
1721 | + ), '', $output ); |
|
1722 | + } |
|
1723 | + |
|
1724 | + /** |
|
1725 | + * Convert an array of attributes to block string. |
|
1726 | + * |
|
1727 | + * @todo there is prob a faster way to do this, also we could add some validation here. |
|
1728 | + * |
|
1729 | + * @param $custom_attributes |
|
1730 | + * |
|
1731 | + * @return string |
|
1732 | + */ |
|
1733 | + public function array_to_attributes( $custom_attributes, $html = false ) { |
|
1734 | + $attributes = ''; |
|
1735 | + if ( ! empty( $custom_attributes ) ) { |
|
1736 | + |
|
1737 | + if ( $html ) { |
|
1738 | + foreach ( $custom_attributes as $key => $val ) { |
|
1739 | + $attributes .= " $key='$val' "; |
|
1740 | + } |
|
1741 | + } else { |
|
1742 | + foreach ( $custom_attributes as $key => $val ) { |
|
1743 | + $attributes .= "'$key': '$val',"; |
|
1744 | + } |
|
1745 | + } |
|
1746 | + } |
|
1747 | + |
|
1748 | + return $attributes; |
|
1749 | + } |
|
1750 | + |
|
1751 | + /** |
|
1752 | + * A self looping function to create the output for JS block elements. |
|
1753 | + * |
|
1754 | + * This is what is output in the WP Editor visual view. |
|
1755 | + * |
|
1756 | + * @param $args |
|
1757 | + */ |
|
1758 | + public function block_element( $args ) { |
|
1759 | + |
|
1760 | + |
|
1761 | + if ( ! empty( $args ) ) { |
|
1762 | + foreach ( $args as $element => $new_args ) { |
|
1763 | + |
|
1764 | + if ( is_array( $new_args ) ) { // its an element |
|
1765 | + |
|
1766 | + |
|
1767 | + if ( isset( $new_args['element'] ) ) { |
|
1768 | + |
|
1769 | + if ( isset( $new_args['element_require'] ) ) { |
|
1770 | + echo str_replace( array( |
|
1771 | + "'+", |
|
1772 | + "+'" |
|
1773 | + ), '', $this->block_props_replace( $new_args['element_require'] ) ) . " && "; |
|
1774 | + unset( $new_args['element_require'] ); |
|
1775 | + } |
|
1776 | + |
|
1777 | + echo "\n el( '" . $new_args['element'] . "', {"; |
|
1778 | + |
|
1779 | + // get the attributes |
|
1780 | + foreach ( $new_args as $new_key => $new_value ) { |
|
1781 | + |
|
1782 | + |
|
1783 | + if ( $new_key == 'element' || $new_key == 'content' || $new_key == 'element_require' || $new_key == 'element_repeat' || is_array( $new_value ) ) { |
|
1784 | + // do nothing |
|
1785 | + } else { |
|
1786 | + echo $this->block_element( array( $new_key => $new_value ) ); |
|
1787 | + } |
|
1788 | + } |
|
1789 | + |
|
1790 | + echo "},";// end attributes |
|
1791 | + |
|
1792 | + // get the content |
|
1793 | + $first_item = 0; |
|
1794 | + foreach ( $new_args as $new_key => $new_value ) { |
|
1795 | + if ( $new_key === 'content' || is_array( $new_value ) ) { |
|
1796 | + |
|
1797 | + if ( $new_key === 'content' ) { |
|
1798 | + echo "'" . $this->block_props_replace( $new_value ) . "'"; |
|
1799 | + } |
|
1800 | + |
|
1801 | + if ( is_array( $new_value ) ) { |
|
1802 | + |
|
1803 | + if ( isset( $new_value['element_require'] ) ) { |
|
1804 | + echo str_replace( array( |
|
1805 | + "'+", |
|
1806 | + "+'" |
|
1807 | + ), '', $this->block_props_replace( $new_value['element_require'] ) ) . " && "; |
|
1808 | + unset( $new_value['element_require'] ); |
|
1809 | + } |
|
1810 | + |
|
1811 | + if ( isset( $new_value['element_repeat'] ) ) { |
|
1812 | + $x = 1; |
|
1813 | + while ( $x <= absint( $new_value['element_repeat'] ) ) { |
|
1814 | + $this->block_element( array( '' => $new_value ) ); |
|
1815 | + $x ++; |
|
1816 | + } |
|
1817 | + } else { |
|
1818 | + $this->block_element( array( '' => $new_value ) ); |
|
1819 | + } |
|
1820 | + } |
|
1821 | + $first_item ++; |
|
1822 | + } |
|
1823 | + } |
|
1824 | + |
|
1825 | + echo ")";// end content |
|
1826 | + |
|
1827 | + echo ", \n"; |
|
1828 | + |
|
1829 | + } |
|
1830 | + } else { |
|
1831 | + |
|
1832 | + if ( substr( $element, 0, 3 ) === "if_" ) { |
|
1833 | + echo str_replace( "if_", "", $element ) . ": " . $this->block_props_replace( $new_args, true ) . ","; |
|
1834 | + } elseif ( $element == 'style' ) { |
|
1835 | + echo $element . ": " . $this->block_props_replace( $new_args ) . ","; |
|
1836 | + } else { |
|
1837 | + echo $element . ": '" . $this->block_props_replace( $new_args ) . "',"; |
|
1838 | + } |
|
1839 | + |
|
1840 | + } |
|
1841 | + } |
|
1842 | + } |
|
1843 | + } |
|
1844 | + |
|
1845 | + /** |
|
1846 | + * Replace block attributes placeholders with the proper naming. |
|
1847 | + * |
|
1848 | + * @param $string |
|
1849 | + * |
|
1850 | + * @return mixed |
|
1851 | + */ |
|
1852 | + public function block_props_replace( $string, $no_wrap = false ) { |
|
1853 | + |
|
1854 | + if ( $no_wrap ) { |
|
1855 | + $string = str_replace( array( "[%", "%]" ), array( "props.attributes.", "" ), $string ); |
|
1856 | + } else { |
|
1857 | + $string = str_replace( array( "[%", "%]" ), array( "'+props.attributes.", "+'" ), $string ); |
|
1858 | + } |
|
1859 | + |
|
1860 | + return $string; |
|
1861 | + } |
|
1862 | + |
|
1863 | + /** |
|
1864 | + * Outputs the content of the widget |
|
1865 | + * |
|
1866 | + * @param array $args |
|
1867 | + * @param array $instance |
|
1868 | + */ |
|
1869 | + public function widget( $args, $instance ) { |
|
1870 | + |
|
1871 | + // get the filtered values |
|
1872 | + $argument_values = $this->argument_values( $instance ); |
|
1873 | + $argument_values = $this->string_to_bool( $argument_values ); |
|
1874 | + $output = $this->output( $argument_values, $args ); |
|
1875 | + |
|
1876 | + if ( $output ) { |
|
1877 | + // Before widget |
|
1878 | + $before_widget = $args['before_widget']; |
|
1879 | + $before_widget = apply_filters( 'wp_super_duper_before_widget', $before_widget, $args, $instance, $this ); |
|
1880 | + $before_widget = apply_filters( 'wp_super_duper_before_widget_' . $this->base_id, $before_widget, $args, $instance, $this ); |
|
1881 | + |
|
1882 | + // After widget |
|
1883 | + $after_widget = $args['after_widget']; |
|
1884 | + $after_widget = apply_filters( 'wp_super_duper_after_widget', $after_widget, $args, $instance, $this ); |
|
1885 | + $after_widget = apply_filters( 'wp_super_duper_after_widget_' . $this->base_id, $after_widget, $args, $instance, $this ); |
|
1886 | + |
|
1887 | + echo $before_widget; |
|
1888 | + // elementor strips the widget wrapping div so we check for and add it back if needed |
|
1889 | + if ( $this->is_elementor_widget_output() ) { |
|
1890 | + echo ! empty( $this->options['widget_ops']['classname'] ) ? "<span class='" . esc_attr( $this->options['widget_ops']['classname'] ) . "'>" : ''; |
|
1891 | + } |
|
1892 | + echo $this->output_title( $args, $instance ); |
|
1893 | + echo $output; |
|
1894 | + if ( $this->is_elementor_widget_output() ) { |
|
1895 | + echo ! empty( $this->options['widget_ops']['classname'] ) ? "</span>" : ''; |
|
1896 | + } |
|
1897 | + echo $after_widget; |
|
1898 | + } elseif ( $this->is_preview() && $output == '' ) {// if preview show a placeholder if empty |
|
1899 | + $output = $this->preview_placeholder_text( "{{" . $this->base_id . "}}" ); |
|
1900 | + echo $output; |
|
1901 | + } |
|
1902 | + } |
|
1903 | + |
|
1904 | + /** |
|
1905 | + * Tests if the current output is inside a elementor container. |
|
1906 | + * |
|
1907 | + * @since 1.0.4 |
|
1908 | + * @return bool |
|
1909 | + */ |
|
1910 | + public function is_elementor_widget_output() { |
|
1911 | + $result = false; |
|
1912 | + if ( defined( 'ELEMENTOR_VERSION' ) && isset( $this->number ) && $this->number == 'REPLACE_TO_ID' ) { |
|
1913 | + $result = true; |
|
1914 | + } |
|
1915 | + |
|
1916 | + return $result; |
|
1917 | + } |
|
1918 | + |
|
1919 | + /** |
|
1920 | + * Tests if the current output is inside a elementor preview. |
|
1921 | + * |
|
1922 | + * @since 1.0.4 |
|
1923 | + * @return bool |
|
1924 | + */ |
|
1925 | + public function is_elementor_preview() { |
|
1926 | + $result = false; |
|
1927 | + if ( isset( $_REQUEST['elementor-preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) || ( isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor_ajax' ) ) { |
|
1928 | + $result = true; |
|
1929 | + } |
|
1930 | + |
|
1931 | + return $result; |
|
1932 | + } |
|
1933 | + |
|
1934 | + /** |
|
1935 | + * Tests if the current output is inside a Divi preview. |
|
1936 | + * |
|
1937 | + * @since 1.0.6 |
|
1938 | + * @return bool |
|
1939 | + */ |
|
1940 | + public function is_divi_preview() { |
|
1941 | + $result = false; |
|
1942 | + if ( isset( $_REQUEST['et_fb'] ) || isset( $_REQUEST['et_pb_preview'] ) || ( is_admin() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'elementor' ) ) { |
|
1943 | + $result = true; |
|
1944 | + } |
|
1945 | + |
|
1946 | + return $result; |
|
1947 | + } |
|
1948 | + |
|
1949 | + /** |
|
1950 | + * Tests if the current output is inside a Beaver builder preview. |
|
1951 | + * |
|
1952 | + * @since 1.0.6 |
|
1953 | + * @return bool |
|
1954 | + */ |
|
1955 | + public function is_beaver_preview() { |
|
1956 | + $result = false; |
|
1957 | + if ( isset( $_REQUEST['fl_builder'] ) ) { |
|
1958 | + $result = true; |
|
1959 | + } |
|
1960 | + |
|
1961 | + return $result; |
|
1962 | + } |
|
1963 | + |
|
1964 | + /** |
|
1965 | + * Tests if the current output is inside a siteorigin builder preview. |
|
1966 | + * |
|
1967 | + * @since 1.0.6 |
|
1968 | + * @return bool |
|
1969 | + */ |
|
1970 | + public function is_siteorigin_preview() { |
|
1971 | + $result = false; |
|
1972 | + if ( ! empty( $_REQUEST['siteorigin_panels_live_editor'] ) ) { |
|
1973 | + $result = true; |
|
1974 | + } |
|
1975 | + |
|
1976 | + return $result; |
|
1977 | + } |
|
1978 | + |
|
1979 | + /** |
|
1980 | + * Tests if the current output is inside a cornerstone builder preview. |
|
1981 | + * |
|
1982 | + * @since 1.0.8 |
|
1983 | + * @return bool |
|
1984 | + */ |
|
1985 | + public function is_cornerstone_preview() { |
|
1986 | + $result = false; |
|
1987 | + if ( ! empty( $_REQUEST['cornerstone_preview'] ) || basename( $_SERVER['REQUEST_URI'] ) == 'cornerstone-endpoint' ) { |
|
1988 | + $result = true; |
|
1989 | + } |
|
1990 | + |
|
1991 | + return $result; |
|
1992 | + } |
|
1993 | + |
|
1994 | + /** |
|
1995 | + * General function to check if we are in a preview situation. |
|
1996 | + * |
|
1997 | + * @since 1.0.6 |
|
1998 | + * @return bool |
|
1999 | + */ |
|
2000 | + public function is_preview() { |
|
2001 | + $preview = false; |
|
2002 | + if ( $this->is_divi_preview() ) { |
|
2003 | + $preview = true; |
|
2004 | + } elseif ( $this->is_elementor_preview() ) { |
|
2005 | + $preview = true; |
|
2006 | + } elseif ( $this->is_beaver_preview() ) { |
|
2007 | + $preview = true; |
|
2008 | + } elseif ( $this->is_siteorigin_preview() ) { |
|
2009 | + $preview = true; |
|
2010 | + } elseif ( $this->is_cornerstone_preview() ) { |
|
2011 | + $preview = true; |
|
2012 | + } |
|
2013 | + |
|
2014 | + return $preview; |
|
2015 | + } |
|
2016 | + |
|
2017 | + /** |
|
2018 | + * Output the super title. |
|
2019 | + * |
|
2020 | + * @param $args |
|
2021 | + * @param array $instance |
|
2022 | + * |
|
2023 | + * @return string |
|
2024 | + */ |
|
2025 | + public function output_title( $args, $instance = array() ) { |
|
2026 | + $output = ''; |
|
2027 | + if ( ! empty( $instance['title'] ) ) { |
|
2028 | + /** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */ |
|
2029 | + $title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ); |
|
2030 | + $output = $args['before_title'] . $title . $args['after_title']; |
|
2031 | + } |
|
2032 | + |
|
2033 | + return $output; |
|
2034 | + } |
|
2035 | + |
|
2036 | + /** |
|
2037 | + * Outputs the options form inputs for the widget. |
|
2038 | + * |
|
2039 | + * @param array $instance The widget options. |
|
2040 | + */ |
|
2041 | + public function form( $instance ) { |
|
2042 | + |
|
2043 | + // set widget instance |
|
2044 | + $this->instance = $instance; |
|
2045 | + |
|
2046 | + // set it as a SD widget |
|
2047 | + echo $this->widget_advanced_toggle(); |
|
2048 | + |
|
2049 | + echo "<p>" . esc_attr( $this->options['widget_ops']['description'] ) . "</p>"; |
|
2050 | + $arguments = $this->get_arguments(); |
|
2051 | + |
|
2052 | + if ( is_array( $arguments ) ) { |
|
2053 | + foreach ( $arguments as $key => $args ) { |
|
2054 | + $this->widget_inputs( $args, $instance ); |
|
2055 | + } |
|
2056 | + } |
|
2057 | + } |
|
2058 | + |
|
2059 | + /** |
|
2060 | + * Get the hidden input that when added makes the advanced button show on widget settings. |
|
2061 | + * |
|
2062 | + * @return string |
|
2063 | + */ |
|
2064 | + public function widget_advanced_toggle() { |
|
2065 | + |
|
2066 | + $output = ''; |
|
2067 | + if ( $this->block_show_advanced() ) { |
|
2068 | + $val = 1; |
|
2069 | + } else { |
|
2070 | + $val = 0; |
|
2071 | + } |
|
2072 | + |
|
2073 | + $output .= "<input type='hidden' class='sd-show-advanced' value='$val' />"; |
|
2074 | + |
|
2075 | + return $output; |
|
2076 | + } |
|
2077 | + |
|
2078 | + /** |
|
2079 | + * Convert require element. |
|
2080 | + * |
|
2081 | + * @since 1.0.0 |
|
2082 | + * |
|
2083 | + * @param string $input Input element. |
|
2084 | + * |
|
2085 | + * @return string $output |
|
2086 | + */ |
|
2087 | + public function convert_element_require( $input ) { |
|
2088 | + |
|
2089 | + $input = str_replace( "'", '"', $input );// we only want double quotes |
|
2090 | + |
|
2091 | + $output = esc_attr( str_replace( array( "[%", "%]" ), array( |
|
2092 | + "jQuery(form).find('[data-argument=\"", |
|
2093 | + "\"]').find('input,select').val()" |
|
2094 | + ), $input ) ); |
|
2095 | + |
|
2096 | + return $output; |
|
2097 | + } |
|
2098 | + |
|
2099 | + /** |
|
2100 | + * Builds the inputs for the widget options. |
|
2101 | + * |
|
2102 | + * @param $args |
|
2103 | + * @param $instance |
|
2104 | + */ |
|
2105 | + public function widget_inputs( $args, $instance ) { |
|
2106 | + |
|
2107 | + $class = ""; |
|
2108 | + $element_require = ""; |
|
2109 | + $custom_attributes = ""; |
|
2110 | + |
|
2111 | + // get value |
|
2112 | + if ( isset( $instance[ $args['name'] ] ) ) { |
|
2113 | + $value = $instance[ $args['name'] ]; |
|
2114 | + } elseif ( ! isset( $instance[ $args['name'] ] ) && ! empty( $args['default'] ) ) { |
|
2115 | + $value = is_array( $args['default'] ) ? array_map( "esc_html", $args['default'] ) : esc_html( $args['default'] ); |
|
2116 | + } else { |
|
2117 | + $value = ''; |
|
2118 | + } |
|
2119 | + |
|
2120 | + // get placeholder |
|
2121 | + if ( ! empty( $args['placeholder'] ) ) { |
|
2122 | + $placeholder = "placeholder='" . esc_html( $args['placeholder'] ) . "'"; |
|
2123 | + } else { |
|
2124 | + $placeholder = ''; |
|
2125 | + } |
|
2126 | + |
|
2127 | + // get if advanced |
|
2128 | + if ( isset( $args['advanced'] ) && $args['advanced'] ) { |
|
2129 | + $class .= " sd-advanced-setting "; |
|
2130 | + } |
|
2131 | + |
|
2132 | + // element_require |
|
2133 | + if ( isset( $args['element_require'] ) && $args['element_require'] ) { |
|
2134 | + $element_require = $args['element_require']; |
|
2135 | + } |
|
2136 | + |
|
2137 | + // custom_attributes |
|
2138 | + if ( isset( $args['custom_attributes'] ) && $args['custom_attributes'] ) { |
|
2139 | + $custom_attributes = $this->array_to_attributes( $args['custom_attributes'], true ); |
|
2140 | + } |
|
2141 | + |
|
2142 | + // before wrapper |
|
2143 | + ?> |
|
2144 | 2144 | <p class="sd-argument <?php echo esc_attr( $class ); ?>" |
2145 | 2145 | data-argument='<?php echo esc_attr( $args['name'] ); ?>' |
2146 | 2146 | data-element_require='<?php if ( $element_require ) { |
2147 | - echo $this->convert_element_require( $element_require ); |
|
2148 | - } ?>' |
|
2147 | + echo $this->convert_element_require( $element_require ); |
|
2148 | + } ?>' |
|
2149 | 2149 | > |
2150 | 2150 | <?php |
2151 | 2151 | |
2152 | - switch ( $args['type'] ) { |
|
2153 | - //array('text','password','number','email','tel','url','color') |
|
2154 | - case "text": |
|
2155 | - case "password": |
|
2156 | - case "number": |
|
2157 | - case "email": |
|
2158 | - case "tel": |
|
2159 | - case "url": |
|
2160 | - case "color": |
|
2161 | - ?> |
|
2152 | + switch ( $args['type'] ) { |
|
2153 | + //array('text','password','number','email','tel','url','color') |
|
2154 | + case "text": |
|
2155 | + case "password": |
|
2156 | + case "number": |
|
2157 | + case "email": |
|
2158 | + case "tel": |
|
2159 | + case "url": |
|
2160 | + case "color": |
|
2161 | + ?> |
|
2162 | 2162 | <label |
2163 | 2163 | 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> |
2164 | 2164 | <input <?php echo $placeholder; ?> class="widefat" |
@@ -2169,47 +2169,47 @@ discard block |
||
2169 | 2169 | value="<?php echo esc_attr( $value ); ?>"> |
2170 | 2170 | <?php |
2171 | 2171 | |
2172 | - break; |
|
2173 | - case "select": |
|
2174 | - $multiple = isset( $args['multiple'] ) && $args['multiple'] ? true : false; |
|
2175 | - if ( $multiple ) { |
|
2176 | - if ( empty( $value ) ) { |
|
2177 | - $value = array(); |
|
2178 | - } |
|
2179 | - } |
|
2180 | - ?> |
|
2172 | + break; |
|
2173 | + case "select": |
|
2174 | + $multiple = isset( $args['multiple'] ) && $args['multiple'] ? true : false; |
|
2175 | + if ( $multiple ) { |
|
2176 | + if ( empty( $value ) ) { |
|
2177 | + $value = array(); |
|
2178 | + } |
|
2179 | + } |
|
2180 | + ?> |
|
2181 | 2181 | <label |
2182 | 2182 | 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> |
2183 | 2183 | <select <?php echo $placeholder; ?> class="widefat" |
2184 | 2184 | <?php echo $custom_attributes; ?> |
2185 | 2185 | id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
2186 | 2186 | name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); |
2187 | - if ( $multiple ) { |
|
2188 | - echo "[]"; |
|
2189 | - } ?>" |
|
2187 | + if ( $multiple ) { |
|
2188 | + echo "[]"; |
|
2189 | + } ?>" |
|
2190 | 2190 | <?php if ( $multiple ) { |
2191 | - echo "multiple"; |
|
2192 | - } //@todo not implemented yet due to gutenberg not supporting it |
|
2193 | - ?> |
|
2191 | + echo "multiple"; |
|
2192 | + } //@todo not implemented yet due to gutenberg not supporting it |
|
2193 | + ?> |
|
2194 | 2194 | > |
2195 | 2195 | <?php |
2196 | 2196 | |
2197 | - if ( ! empty( $args['options'] ) ) { |
|
2198 | - foreach ( $args['options'] as $val => $label ) { |
|
2199 | - if ( $multiple ) { |
|
2200 | - $selected = in_array( $val, $value ) ? 'selected="selected"' : ''; |
|
2201 | - } else { |
|
2202 | - $selected = selected( $value, $val, false ); |
|
2203 | - } |
|
2204 | - echo "<option value='$val' " . $selected . ">$label</option>"; |
|
2205 | - } |
|
2206 | - } |
|
2207 | - ?> |
|
2197 | + if ( ! empty( $args['options'] ) ) { |
|
2198 | + foreach ( $args['options'] as $val => $label ) { |
|
2199 | + if ( $multiple ) { |
|
2200 | + $selected = in_array( $val, $value ) ? 'selected="selected"' : ''; |
|
2201 | + } else { |
|
2202 | + $selected = selected( $value, $val, false ); |
|
2203 | + } |
|
2204 | + echo "<option value='$val' " . $selected . ">$label</option>"; |
|
2205 | + } |
|
2206 | + } |
|
2207 | + ?> |
|
2208 | 2208 | </select> |
2209 | 2209 | <?php |
2210 | - break; |
|
2211 | - case "checkbox": |
|
2212 | - ?> |
|
2210 | + break; |
|
2211 | + case "checkbox": |
|
2212 | + ?> |
|
2213 | 2213 | <input <?php echo $placeholder; ?> |
2214 | 2214 | <?php checked( 1, $value, true ) ?> |
2215 | 2215 | <?php echo $custom_attributes; ?> |
@@ -2219,136 +2219,136 @@ discard block |
||
2219 | 2219 | <label |
2220 | 2220 | 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> |
2221 | 2221 | <?php |
2222 | - break; |
|
2223 | - case "hidden": |
|
2224 | - ?> |
|
2222 | + break; |
|
2223 | + case "hidden": |
|
2224 | + ?> |
|
2225 | 2225 | <input id="<?php echo esc_attr( $this->get_field_id( $args['name'] ) ); ?>" |
2226 | 2226 | name="<?php echo esc_attr( $this->get_field_name( $args['name'] ) ); ?>" type="hidden" |
2227 | 2227 | value="<?php echo esc_attr( $value ); ?>"> |
2228 | 2228 | <?php |
2229 | - break; |
|
2230 | - default: |
|
2231 | - echo "No input type found!"; // @todo we need to add more input types. |
|
2232 | - } |
|
2229 | + break; |
|
2230 | + default: |
|
2231 | + echo "No input type found!"; // @todo we need to add more input types. |
|
2232 | + } |
|
2233 | 2233 | |
2234 | - // after wrapper |
|
2235 | - ?> |
|
2234 | + // after wrapper |
|
2235 | + ?> |
|
2236 | 2236 | </p> |
2237 | 2237 | <?php |
2238 | 2238 | |
2239 | - } |
|
2240 | - |
|
2241 | - /** |
|
2242 | - * Get the widget input description html. |
|
2243 | - * |
|
2244 | - * @param $args |
|
2245 | - * |
|
2246 | - * @return string |
|
2247 | - * @todo, need to make its own tooltip script |
|
2248 | - */ |
|
2249 | - public function widget_field_desc( $args ) { |
|
2250 | - |
|
2251 | - $description = ''; |
|
2252 | - if ( isset( $args['desc'] ) && $args['desc'] ) { |
|
2253 | - if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) { |
|
2254 | - $description = $this->desc_tip( $args['desc'] ); |
|
2255 | - } else { |
|
2256 | - $description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>'; |
|
2257 | - } |
|
2258 | - } |
|
2259 | - |
|
2260 | - return $description; |
|
2261 | - } |
|
2262 | - |
|
2263 | - /** |
|
2264 | - * Get the tool tip html. |
|
2265 | - * |
|
2266 | - * @param $tip |
|
2267 | - * @param bool $allow_html |
|
2268 | - * |
|
2269 | - * @return string |
|
2270 | - */ |
|
2271 | - function desc_tip( $tip, $allow_html = false ) { |
|
2272 | - if ( $allow_html ) { |
|
2273 | - $tip = $this->sanitize_tooltip( $tip ); |
|
2274 | - } else { |
|
2275 | - $tip = esc_attr( $tip ); |
|
2276 | - } |
|
2277 | - |
|
2278 | - return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>'; |
|
2279 | - } |
|
2280 | - |
|
2281 | - /** |
|
2282 | - * Sanitize a string destined to be a tooltip. |
|
2283 | - * |
|
2284 | - * @param string $var |
|
2285 | - * |
|
2286 | - * @return string |
|
2287 | - */ |
|
2288 | - public function sanitize_tooltip( $var ) { |
|
2289 | - return htmlspecialchars( wp_kses( html_entity_decode( $var ), array( |
|
2290 | - 'br' => array(), |
|
2291 | - 'em' => array(), |
|
2292 | - 'strong' => array(), |
|
2293 | - 'small' => array(), |
|
2294 | - 'span' => array(), |
|
2295 | - 'ul' => array(), |
|
2296 | - 'li' => array(), |
|
2297 | - 'ol' => array(), |
|
2298 | - 'p' => array(), |
|
2299 | - ) ) ); |
|
2300 | - } |
|
2301 | - |
|
2302 | - /** |
|
2303 | - * Processing widget options on save |
|
2304 | - * |
|
2305 | - * @param array $new_instance The new options |
|
2306 | - * @param array $old_instance The previous options |
|
2307 | - * |
|
2308 | - * @return array |
|
2309 | - * @todo we should add some sanitation here. |
|
2310 | - */ |
|
2311 | - public function update( $new_instance, $old_instance ) { |
|
2312 | - |
|
2313 | - //save the widget |
|
2314 | - $instance = array_merge( (array) $old_instance, (array) $new_instance ); |
|
2315 | - |
|
2316 | - // set widget instance |
|
2317 | - $this->instance = $instance; |
|
2318 | - |
|
2319 | - if ( empty( $this->arguments ) ) { |
|
2320 | - $this->get_arguments(); |
|
2321 | - } |
|
2322 | - |
|
2323 | - // check for checkboxes |
|
2324 | - if ( ! empty( $this->arguments ) ) { |
|
2325 | - foreach ( $this->arguments as $argument ) { |
|
2326 | - if ( isset( $argument['type'] ) && $argument['type'] == 'checkbox' && ! isset( $new_instance[ $argument['name'] ] ) ) { |
|
2327 | - $instance[ $argument['name'] ] = '0'; |
|
2328 | - } |
|
2329 | - } |
|
2330 | - } |
|
2331 | - |
|
2332 | - return $instance; |
|
2333 | - } |
|
2334 | - |
|
2335 | - /** |
|
2336 | - * Checks if the current call is a ajax call to get the block content. |
|
2337 | - * |
|
2338 | - * This can be used in your widget to return different content as the block content. |
|
2339 | - * |
|
2340 | - * @since 1.0.3 |
|
2341 | - * @return bool |
|
2342 | - */ |
|
2343 | - public function is_block_content_call() { |
|
2344 | - $result = false; |
|
2345 | - if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) { |
|
2346 | - $result = true; |
|
2347 | - } |
|
2348 | - |
|
2349 | - return $result; |
|
2350 | - } |
|
2351 | - |
|
2352 | - } |
|
2239 | + } |
|
2240 | + |
|
2241 | + /** |
|
2242 | + * Get the widget input description html. |
|
2243 | + * |
|
2244 | + * @param $args |
|
2245 | + * |
|
2246 | + * @return string |
|
2247 | + * @todo, need to make its own tooltip script |
|
2248 | + */ |
|
2249 | + public function widget_field_desc( $args ) { |
|
2250 | + |
|
2251 | + $description = ''; |
|
2252 | + if ( isset( $args['desc'] ) && $args['desc'] ) { |
|
2253 | + if ( isset( $args['desc_tip'] ) && $args['desc_tip'] ) { |
|
2254 | + $description = $this->desc_tip( $args['desc'] ); |
|
2255 | + } else { |
|
2256 | + $description = '<span class="description">' . wp_kses_post( $args['desc'] ) . '</span>'; |
|
2257 | + } |
|
2258 | + } |
|
2259 | + |
|
2260 | + return $description; |
|
2261 | + } |
|
2262 | + |
|
2263 | + /** |
|
2264 | + * Get the tool tip html. |
|
2265 | + * |
|
2266 | + * @param $tip |
|
2267 | + * @param bool $allow_html |
|
2268 | + * |
|
2269 | + * @return string |
|
2270 | + */ |
|
2271 | + function desc_tip( $tip, $allow_html = false ) { |
|
2272 | + if ( $allow_html ) { |
|
2273 | + $tip = $this->sanitize_tooltip( $tip ); |
|
2274 | + } else { |
|
2275 | + $tip = esc_attr( $tip ); |
|
2276 | + } |
|
2277 | + |
|
2278 | + return '<span class="gd-help-tip dashicons dashicons-editor-help" title="' . $tip . '"></span>'; |
|
2279 | + } |
|
2280 | + |
|
2281 | + /** |
|
2282 | + * Sanitize a string destined to be a tooltip. |
|
2283 | + * |
|
2284 | + * @param string $var |
|
2285 | + * |
|
2286 | + * @return string |
|
2287 | + */ |
|
2288 | + public function sanitize_tooltip( $var ) { |
|
2289 | + return htmlspecialchars( wp_kses( html_entity_decode( $var ), array( |
|
2290 | + 'br' => array(), |
|
2291 | + 'em' => array(), |
|
2292 | + 'strong' => array(), |
|
2293 | + 'small' => array(), |
|
2294 | + 'span' => array(), |
|
2295 | + 'ul' => array(), |
|
2296 | + 'li' => array(), |
|
2297 | + 'ol' => array(), |
|
2298 | + 'p' => array(), |
|
2299 | + ) ) ); |
|
2300 | + } |
|
2301 | + |
|
2302 | + /** |
|
2303 | + * Processing widget options on save |
|
2304 | + * |
|
2305 | + * @param array $new_instance The new options |
|
2306 | + * @param array $old_instance The previous options |
|
2307 | + * |
|
2308 | + * @return array |
|
2309 | + * @todo we should add some sanitation here. |
|
2310 | + */ |
|
2311 | + public function update( $new_instance, $old_instance ) { |
|
2312 | + |
|
2313 | + //save the widget |
|
2314 | + $instance = array_merge( (array) $old_instance, (array) $new_instance ); |
|
2315 | + |
|
2316 | + // set widget instance |
|
2317 | + $this->instance = $instance; |
|
2318 | + |
|
2319 | + if ( empty( $this->arguments ) ) { |
|
2320 | + $this->get_arguments(); |
|
2321 | + } |
|
2322 | + |
|
2323 | + // check for checkboxes |
|
2324 | + if ( ! empty( $this->arguments ) ) { |
|
2325 | + foreach ( $this->arguments as $argument ) { |
|
2326 | + if ( isset( $argument['type'] ) && $argument['type'] == 'checkbox' && ! isset( $new_instance[ $argument['name'] ] ) ) { |
|
2327 | + $instance[ $argument['name'] ] = '0'; |
|
2328 | + } |
|
2329 | + } |
|
2330 | + } |
|
2331 | + |
|
2332 | + return $instance; |
|
2333 | + } |
|
2334 | + |
|
2335 | + /** |
|
2336 | + * Checks if the current call is a ajax call to get the block content. |
|
2337 | + * |
|
2338 | + * This can be used in your widget to return different content as the block content. |
|
2339 | + * |
|
2340 | + * @since 1.0.3 |
|
2341 | + * @return bool |
|
2342 | + */ |
|
2343 | + public function is_block_content_call() { |
|
2344 | + $result = false; |
|
2345 | + if ( wp_doing_ajax() && isset( $_REQUEST['action'] ) && $_REQUEST['action'] == 'super_duper_output_shortcode' ) { |
|
2346 | + $result = true; |
|
2347 | + } |
|
2348 | + |
|
2349 | + return $result; |
|
2350 | + } |
|
2351 | + |
|
2352 | + } |
|
2353 | 2353 | |
2354 | 2354 | } |
2355 | 2355 | \ No newline at end of file |