PluginProbe ʕ •ᴥ•ʔ
Shortcodes and extra features for Phlox theme / 2.17.14
Shortcodes and extra features for Phlox theme v2.17.14
2.17.21 2.17.20 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.0.6 1.0.9 1.1.0 1.3.0 1.3.1 1.3.10 1.3.14 1.3.2 1.3.3 1.3.6 1.4.0 1.4.1 1.4.2 1.5.0 1.5.2 1.6.0 1.6.2 1.6.4 1.7.0 1.7.2 2.10.0 2.10.1 2.10.3 2.10.5 2.10.7 2.10.8 2.10.9 2.11.0 2.11.1 2.11.2 2.12.0 2.14.0 2.15.0 2.15.2 2.15.4 2.15.5 2.15.6 2.15.7 2.15.8 2.15.9 2.16.0 2.16.1 2.16.2 2.16.3 2.16.4 2.17.0 2.17.1 2.17.12 2.17.13 2.17.14 2.17.15 2.17.16 2.17.2 2.17.3 2.17.4 2.17.5 2.17.6 2.17.8 2.17.9 2.4.12 2.4.13 2.4.14 2.4.16 2.4.18 2.4.19 2.4.9 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.14 2.5.15 2.5.16 2.5.17 2.5.19 2.5.2 2.5.20 2.5.3 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.10 2.6.12 2.6.13 2.6.14 2.6.15 2.6.16 2.6.17 2.6.19 2.6.2 2.6.20 2.6.4 2.6.5 2.6.7 2.7.0 2.7.1 2.7.10 2.7.11 2.7.12 2.7.13 2.7.14 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.9 2.9.0 2.9.12 2.9.14 2.9.15 2.9.16 2.9.17 2.9.18 2.9.19 2.9.2 2.9.20 2.9.21 2.9.22 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 2.9.8
auxin-elements / includes / classes / class-auxin-widget.php
auxin-elements / includes / classes Last commit date
class-auxels-admin-assets.php 1 year ago class-auxels-archive-menu-links.php 1 year ago class-auxels-envato-elements.php 1 year ago class-auxels-import-parser.php 3 years ago class-auxels-import.php 3 years ago class-auxels-search-post-type.php 6 months ago class-auxels-wc-attribute-nav-menu.php 1 year ago class-auxin-admin-dashboard.php 1 year ago class-auxin-demo-importer.php 6 months ago class-auxin-dependency-sorting.php 3 years ago class-auxin-import.php 1 year ago class-auxin-install.php 1 year ago class-auxin-master-nav-menu-admin.php 1 year ago class-auxin-page-template.php 1 year ago class-auxin-permalink.php 1 year ago class-auxin-plugin-requirements.php 3 years ago class-auxin-post-type-base.php 1 year ago class-auxin-svg-support-allowedattributes.php 7 years ago class-auxin-svg-support-allowedtags.php 7 years ago class-auxin-svg-support.php 1 year ago class-auxin-walker-nav-menu-back.php 1 year ago class-auxin-welcome-sections.php 1 year ago class-auxin-welcome.php 6 months ago class-auxin-whitelabel.php 3 years ago class-auxin-widget-indie.php 1 year ago class-auxin-widget-shortcode-map.php 11 months ago class-auxin-widget.php 1 year ago
class-auxin-widget.php
522 lines
1 <?php
2 /**
3 * A class for creating widgets dynamically base of Master widget list
4 *
5 *
6 * @package Auxin
7 * @license LICENSE.txt
8 * @author averta
9 * @link http://phlox.pro/
10 * @copyright (c) 2010-2025 averta
11 */
12
13 // no direct access allowed
14 if ( ! defined('ABSPATH') ) exit;
15
16 /*--------------------------------*/
17
18
19 if( ! class_exists( 'Auxin_Widget' ) ) :
20
21
22 class Auxin_Widget extends WP_Widget {
23
24 private $defaults = array();
25 public $fields = array();
26
27 public $widget_fun_name;
28
29 private $dependency_list = array();
30 private $widget_info;
31
32 private $attach_ids_list = null;
33 private $att_ids = null;
34
35 /**
36 * Sets up the widgets name, Id, description and etc
37 */
38 public function __construct( $widget_info ) {
39
40 parent::__construct( $widget_info['base_ID'] , $name = $widget_info['name'], $widget_info['args'] );
41
42 $this->widget_info = $widget_info;
43 $this->fields = $widget_info['params'];
44 $this->widget_fun_name = $widget_info['auxin_output_callback'];
45
46 $this->set_defaults();
47 }
48
49
50 private function set_defaults(){
51 foreach ( $this->fields as $field ) {
52 $this->defaults[ $field["id"] ] = $field["value"];
53 }
54 $this->defaults[ '__uid' ] = $this->widget_info['base_ID'] . '_' . substr( uniqid( ''. wp_rand() ), -8 );
55 }
56
57 //
58 /**
59 * Outputs the content of the widget
60 *
61 * @param array $args The field keys and their real values
62 * @param array $instance The widget name, id and global configs
63 * @return string The widget output for front-end
64 */
65 public function widget( $args, $instance ) {
66 // if the 'widget_info' was available in passed array, we can determine
67 // whether the array is from widget class or not
68
69 // make sure to pass same class name for wrapper to widget too
70 if( isset( $this->widget_info['base_class'] ) ){
71 $args['base_class'] = $this->widget_info['base_class'];
72 }
73 $instance['widget_info'] = $args;
74
75 if( function_exists( $this->widget_fun_name ) ){
76 echo call_user_func( $this->widget_fun_name, $instance );
77 } else {
78 auxin_error( __('The callback for widget does not exists.', 'auxin-elements') );
79 }
80 }
81
82
83 /**
84 * Outputs the options form on admin
85 *
86 * @param array $instance The widget options
87 */
88 public function form( $instance ) {
89 $instance = wp_parse_args( (array) $instance, $this->defaults );
90
91 echo '<div id="' . esc_attr( $this->defaults[ '__uid' ] ) . '" class="auxin-admin-widget-wrapper">';
92
93 // creates id attributes for fields to be saved by update()
94 foreach ( $this->fields as $field ) {
95 $id = $field['id'];
96 // make sure description is set
97 $field["description"] = ! isset( $field["description"] ) ? '': $field["description"];
98
99 $this->watch_for_field_dependencies( $field );
100
101 switch ( $field['type'] ) {
102
103 case 'aux_taxonomy':
104
105 $categories = get_terms( array(
106 'taxonomy' => $field['taxonomy'],
107 'orderby' => 'count',
108 'hide_empty' => true
109 ));
110
111
112 $categories_list = array( ' ' => __('All Categories', 'auxin-elements' ) ) ;
113 foreach ( $categories as $key => $value ) {
114 $categories_list[ $value->term_id ] = $value->name;
115 }
116
117 if( gettype( $instance[ $id ] ) === "string" ) {
118 $select = array( $instance[ $id ] );
119 } else {
120 $select = $instance[ $id ];
121 }
122
123 echo '<div class="aux-element-field aux-multiple-selector ">',
124 '<label for="' . esc_attr( $this->get_field_id($id) ) . '" >'. esc_html( $field["name"] ) .'</label>',
125 '<select multiple="multiple" name="' . esc_attr( $this->get_field_name($id) ) . '" id="' . esc_attr( $this->get_field_name($id) ) . '" class="aux-orig-select2 aux-admin-select2 aux-select2-multiple">';
126 echo '<option value="">' . esc_html__('Choose ..', 'auxin-elements') . '</option>';
127
128 foreach ( $categories_list as $key => $value ) {
129 printf(
130 '<option value="%s" class="hot-topic" %s style="margin-bottom:3px;">%s</option>',
131 esc_attr( $key ),
132 in_array( $key, $select) ? 'selected="selected"' : '',
133 esc_html( $value )
134 );
135 }
136
137 echo '</select>';
138 if ( $field["description"] ) {
139 echo '<p class="option-description">' . esc_html( $field["description"] ) . '</p>';
140 }
141 echo '</div>';
142
143 break;
144
145 case 'iconpicker':
146 case 'aux_iconpicker':
147 $font_icons = Auxin()->Font_Icons->get_icons_list('fontastic');
148 echo '<div class="aux-element-field aux-iconpicker">';
149 echo '<label for="'. esc_attr( $this->get_field_name($id) ).'" >'. esc_html( $field["name"] ).'</label><br />';
150 echo sprintf( '<select name="%1$s" id="%1$s" class="aux-fonticonpicker aux-select" >', esc_attr( $this->get_field_name($id) ) );
151 echo '<option value="">' . esc_html__('Choose ..', 'auxin-elements') . '</option>';
152
153 if( is_array( $font_icons ) ){
154 foreach ( $font_icons as $icon ) {
155 $icon_id = trim( $icon->classname, '.' );
156 echo '<option value="'. esc_attr( $icon_id ) .'" '. selected( $instance[$id], $icon_id, false ) .' >'. esc_html( $icon->name ) . '</option>';
157
158 }
159 }
160
161 echo '</select>';
162 if ( $field["description"] ) {
163 echo '<p class="option-description">' . esc_html( $field["description"] ) . '</p>';
164 }
165 echo '</div>';
166
167 break;
168
169
170
171 case 'textarea_html':
172 case 'textarea_raw_html':
173 echo '<div class="aux-element-field aux-visual-selector">',
174 '<label for="'.esc_attr( $this->get_field_id($id) ).'" >'. esc_html( $field["name"] ).'</label>',
175 '<textarea class="widefat" id="'.esc_attr( $this->get_field_id($id) ).'" name="'.esc_attr( $this->get_field_name($id) ).'" name="'. esc_attr( $this->get_field_name($id) ) .'">',
176 wp_kses_post( $instance[$id] ).'</textarea>';
177 if ( $field["description"] ) {
178 echo '<p class="option-description textarea-desc">' . esc_html( $field["description"] ) . '</p>';
179 }
180 echo '</div>';
181 break;
182
183 case 'textbox':
184 case 'textfield':
185 echo '<div class="aux-element-field aux-visual-selector">',
186 '<label for="'. esc_attr( $this->get_field_id($id) ) .'" >'. esc_html( $field["name"] ).'</label>',
187 '<input class="widefat" id="'. esc_attr( $this->get_field_id($id) ) .'" name="'. esc_attr( $this->get_field_name($id) ) .'" type="text" value="'. esc_attr( $instance[$id] ) .'" />';
188 if ( $field["description"] ) {
189 echo '<p class="option-description">' . esc_html( $field["description"] ) . '</p>';
190 }
191 echo '</div>';
192 break;
193
194 case 'dropdown':
195 case 'select':
196 if( is_array( $instance[$id] ) ){
197 if( ! empty( $instance['def_value'] ) ){
198 $current_value = $instance['def_value'];
199 } else {
200 $default_value = array_keys( $instance[ $id ] );
201 $current_value = $default_value[0];
202 }
203 } else {
204 $current_value = $instance[ $id ];
205 }
206 echo '<div class="aux-element-field aux-dropdown">',
207 '<label for="'. esc_attr( $this->get_field_id( $id ) ) .'" >'. esc_html( $field['name'] ) . '</label>',
208 '<select name="' . esc_attr( $this->get_field_name( $id ) ) . '" id="' . esc_attr( $this->get_field_id( $id ) ) . '" value="' . esc_attr( $current_value ) . '" >';
209 foreach ( $field['options'] as $key => $value ) {
210 printf( '<option value="%s" %s >%s</option>', esc_attr( $key ), selected( $current_value, $key, false ), esc_html( $value ) );
211 }
212 echo '</select>';
213
214 if ( $field["description"] ) {
215 echo '<p class="option-description">' . esc_html( $field["description"] ) . '</p>';
216 }
217 echo '</div>';
218 break;
219
220 // Select2 single
221 case 'aux_select2_single' :
222 if( is_array( $instance[$id] ) ){
223 if( ! empty( $instance['def_value'] ) ){
224 $current_value = $instance['def_value'];
225 } else {
226 $default_value = array_keys( $instance[ $id ] );
227 $current_value = $default_value[0];
228 }
229 } else {
230 $current_value = $instance[ $id ];
231 }
232 echo '<div class="aux-element-field aux-multiple-selector ">',
233 '<label for="'. esc_attr( $this->get_field_id($id) ) .'" >'. esc_html( $field["name"] ) .'</label>',
234 '<div class="section-row-right" >' ,
235 '<select name="'. esc_attr( $this->get_field_name($id) ) .'" id="'. esc_attr( $this->get_field_id($id) ) .'" class="aux-orig-select2 aux-admin-select2 aux-select2-single" data-value="'. esc_attr( $current_value ) .'" value="'. esc_attr( $current_value ) .'" style="width:150px" >';
236 foreach ( $field['options'] as $key => $value ) {
237 printf( '<option value="%s" %s >%s</option>', esc_attr( $key ), selected( $current_value, $key, false ), esc_html( $value ) );
238 }
239 echo '</select></div>';
240 if ( $field["description"] ) {
241 echo '<p class="option-description">' . esc_html( $field["description"] ) . '</p>';
242 }
243 echo '</div>' ;
244 break;
245
246 // defining of aux_select2_multiple field type for widget.
247 case 'aux_select2_multiple' :
248
249 if( gettype( $instance[ $id ] ) ==="string" ) {
250 $select = explode( ',', $instance[ $id ] );
251 } else {
252 $select = $instance[ $id ];
253 }
254
255 echo '<div class="aux-element-field aux-multiple-selector ">';
256 echo '<select multiple="multiple" name="'. esc_attr( $this->get_field_name($id) ) .'" id="'. esc_attr( $this->get_field_id($id) ) .'" style="width:100%" ' . ' class="wpb-multiselect wpb_vc_param_value aux-select2-multiple ' . esc_sql( $field['id'] ) . ' ' . esc_attr( $field['type'] ) . '_field">';
257
258 foreach ( $field['options'] as $key => $value ) {
259 $active_attr = in_array( $key, $select) ? 'selected="selected"' : '';
260 echo sprintf( '<option value="%s" %s >%s</option>', esc_attr( $key ), $active_attr, esc_html( $value ) );
261 }
262
263 echo '</select>';
264
265 if ( $field["description"] ) {
266
267 echo '<p class="option-description">' . esc_html( $field["description"] ) . '</p>';
268 }
269
270 echo '</div>' ;
271
272 break;
273
274 case 'aux_visual_select':
275 echo '<div class="aux-element-field aux-visual-selector">';
276 echo '<label for="'. esc_attr( $this->get_field_id($id) ) .'" >'. esc_html( $field["name"] ) .'</label>';
277 echo '<select class="meta-select visual-select-wrapper" name="' . esc_attr( $this->get_field_name( $id ) ) . '" id="' . esc_attr( $this->get_field_id( $id ) ) . '" value="' . esc_attr( $instance[$id] ) . '" >';
278
279 $tmp_instance_id = $instance[$id];
280 foreach ( $field['choices'] as $id => $option_info ) {
281
282 echo sprintf( '<option value="%s" %s %s %s %s>%s</option>',
283 esc_attr( $id ),
284 ( $tmp_instance_id == $id ? ' selected ' : "" ),
285 ( empty( $option_info['css_class'] ) && ! empty( $option_info['image'] ) ? 'data-symbol="'. esc_attr( $option_info['image'] ) .'"' : '' ),
286 ( ! empty( $option_info['video_src'] ) ? 'data-video-src="'. esc_attr( $option_info['video_src'] ).'"' : '' ),
287 ( ! empty( $option_info['css_class'] ) ? 'data-class="'. esc_attr( $option_info['css_class'] ) .'"' : '' ),
288 esc_html( $option_info['label'] )
289 );
290 }
291
292 echo '</select>';
293 if ( $field["description"] ) {
294 echo '<p class="option-description visual-selector-desc">' . esc_html( $field["description"] ) . '</p>';
295 }
296 echo '</div>';
297 break;
298
299 case 'checkbox':
300 case 'aux_switch':
301 $instance[$id] = isset( $instance[$id] ) ? (bool)$instance[$id] : false;
302 $tick = $instance[$id]? 'checked="checked"': '';
303 echo '<div class="aux-element-field aux_switch">',
304 '<input class="hidden_aux_switch" type="hidden" value="0" id="_'. esc_attr( $this->get_field_id($id) ) .'-hidden" name="'. esc_attr( $this->get_field_name($id) ) .'" >',
305 '<input class="checkbox widefat aux_switch" type="checkbox" ' . $tick . ' id="'. esc_attr( $this->get_field_id($id) ) .'" name="'. esc_attr( $this->get_field_name($id) ) .'" >',
306 '<label for="'. esc_attr( $this->get_field_id($id) ) .'" >'. esc_html( $field["name"] ) .'</label>';
307
308 if ( $field["description"] ) {
309 echo '<p class="option-description">' . esc_html( $field["description"] ) . '</p>';
310 }
311 echo '</div>';
312
313 break;
314
315 case 'color':
316 case 'colorpicker':
317 echo '<div class="aux-element-field aux-colorpicker">',
318 '<label for="'. esc_attr( $this->get_field_id($id) ) .'" >'. esc_html( $field["name"] ) .'</label>',
319 '<div class="mini-color-wrapper"><input id="'. esc_attr( $this->get_field_id($id) ) .'" name="'. esc_attr( $this->get_field_name($id) ) .'" type="text"type="text" value="'. esc_attr( $instance[$id] ) .'" ></div>';
320 if ( $field["description"] ) {
321 echo '<p class="option-description">' . esc_html( $field["description"] ) . '</p>';
322 }
323 echo '</div>';
324 break;
325
326 case 'aux_select_image':
327 case 'attach_image':
328 // Store attachment src for avertaAttachMedia field
329 if( !empty($instance[$id]) ) {
330 $att_ids = explode( ',', $instance[$id] );
331 $attach_ids_list = auxin_get_the_resized_attachment_src( $att_ids, 80, 80, true );
332 if(!empty($att_ids)) {
333 printf( "<script>auxin.attachmedia = jQuery.extend( auxin.attachmedia, %s );</script>", wp_json_encode( array_unique( $attach_ids_list ) ) );
334 }
335 }
336 echo '<div class="aux-element-field av3_container aux_select_image axi-attachmedia-wrapper">',
337 '<label for="'. esc_attr( $this->get_field_id($id) ) .'" >'. esc_html( $field["name"] ) .'</label>',
338 '<input type="text" class="white" name="'. esc_attr( $this->get_field_name( $id ) ).'" ' . 'id="'. esc_attr( $this->get_field_id( $id ) ).'" ' . 'value="' . esc_attr( $instance[$id] ) .
339 '" data-media-type="image" data-limit="1" data-multiple="0"
340 data-add-to-list="'. esc_html__('Add Image', 'auxin-elements') .'"
341 data-uploader-submit="'. esc_html__('Add Image', 'auxin-elements') .'"
342 data-uploader-title="'. esc_html__('Select Image', 'auxin-elements') .'"> ';
343 if ( $field["description"] ) {
344 echo '<p class="option-description">' . esc_html( $field["description"] ) . '</p>';
345 }
346 echo '</div>';
347 break;
348
349 case 'aux_select_images':
350 case 'attach_images':
351 // Store attachment src for avertaAttachMedia field
352 if( !empty($instance[$id]) ) {
353 $att_ids = explode( ',', $instance[$id] );
354 $attach_ids_list = auxin_get_the_resized_attachment_src( $att_ids, 80, 80, true );
355 if(!empty($att_ids)) {
356 printf( "<script>auxin.attachmedia = jQuery.extend( auxin.attachmedia, %s );</script>", wp_json_encode( array_unique( $attach_ids_list ) ) );
357 }
358 }
359 echo '<div class="aux-element-field av3_container aux_select_image axi-attachmedia-wrapper">',
360 '<label for="'. esc_attr( $this->get_field_id($id) ) .'" >'. esc_html( $field["name"] ) .'</label>',
361 '<input type="text" class="white" name="'. esc_attr( $this->get_field_name($id) ) .'" ' . 'id="'. esc_attr( $this->get_field_id($id) ) .'" ' . 'value="' . esc_attr( $instance[$id] ) .
362 '" data-media-type="image" data-limit="9999" data-multiple="1"
363 data-add-to-list="'.esc_html__('Add Image', 'auxin-elements').'"
364 data-uploader-submit="'.esc_html__('Add Image', 'auxin-elements').'"
365 data-uploader-title="'.esc_html__('Select Image', 'auxin-elements').'"> ';
366 if ( $field["description"] ) {
367 echo '<p class="option-description">' . esc_html( $field["description"] ) . '</p>';
368 }
369 echo '</div>';
370 break;
371
372 case 'aux_select_video':
373 case 'attach_video':
374
375 // Store attachment src for avertaAttachMedia field
376 if( !empty($instance[$id]) ) {
377 $att_ids = explode( ',', $instance[$id] );
378 $attach_ids_list = auxin_get_the_resized_attachment_src( $att_ids, 80, 80, true );
379 if(!empty($att_ids)) {
380 printf( "<script>auxin.attachmedia = jQuery.extend( auxin.attachmedia, %s );</script>", wp_json_encode( array_unique( $attach_ids_list ) ) );
381 }
382 }
383 echo '<div class="aux-element-field av3_container aux_select_image axi-attachmedia-wrapper">',
384 '<label for="'. esc_attr( $this->get_field_id($id) ) .'" >'. esc_html( $field["name"] ) .'</label>',
385 '<input type="text" class="white" name="'. esc_attr( $this->get_field_name($id) ) .'" ' . 'id="'. esc_attr( $this->get_field_id($id) ) .'" ' . 'value="' . esc_attr( $instance[$id] ) .
386 '" data-media-type="video" data-limit="1" data-multiple="0"
387 data-add-to-list="'.esc_html__('Add Video', 'auxin-elements').'"
388 data-uploader-submit="'.esc_html__('Add Video', 'auxin-elements').'"
389 data-uploader-title="'.esc_html__('Select Video', 'auxin-elements').'"> ';
390 if ( $field["description"] ) {
391 echo '<p class="option-description">' . esc_html( $field["description"] ) . '</p>';
392 }
393 echo '</div>';
394 break;
395
396 case 'aux_select_audio':
397 case 'attach_audio':
398
399 // Store attachment src for avertaAttachMedia field
400 if( !empty($instance[$id]) ) {
401 $att_ids = explode( ',', $instance[$id] );
402 $attach_ids_list = auxin_get_the_resized_attachment_src( $att_ids, 80, 80, true );
403 if(!empty($att_ids)) {
404 printf( "<script>auxin.attachmedia = jQuery.extend( auxin.attachmedia, %s );</script>", wp_json_encode( array_unique( $attach_ids_list ) ) );
405 }
406 }
407 echo '<div class="aux-element-field av3_container aux_select_image axi-attachmedia-wrapper">',
408 '<label for="'. esc_attr( $this->get_field_id($id) ) .'" >'. esc_html( $field["name"] ) .'</label>',
409 '<input type="text" class="white" name="'. esc_attr( $this->get_field_name($id) ) .'" ' . 'id="'. esc_attr( $this->get_field_id($id) ) .'" ' . 'value="' . esc_attr( $instance[$id] ) .
410 '" data-media-type="audio" data-limit="1" data-multiple="0"
411 data-add-to-list="'.esc_html__('Add Audio', 'auxin-elements').'"
412 data-uploader-submit="'.esc_html__('Add Audio', 'auxin-elements').'"
413 data-uploader-title="'.esc_html__('Select Audio', 'auxin-elements').'"> ';
414 if ( $field["description"] ) {
415 echo '<p class="option-description">' . esc_html( $field["description"] ) . '</p>';
416 }
417 echo '</div>';
418
419 default:
420
421 break;
422 }
423
424 }
425
426 echo '</div>';
427
428
429 // axpp( $this->dependency_list );
430 $this->print_dependencies();
431 }
432
433
434 /**
435 * Loop to collect dependency map of metafields
436 *
437 * @param array $field field options
438 * @return void
439 */
440 public function watch_for_field_dependencies( $field = array() ){
441 if( empty( $field ) ){
442 return;
443 }
444
445 $field_dependencies = array();
446
447 if( isset( $field['dependency'] ) && ! empty( $field['dependency'] ) ){
448
449 $depend = $field['dependency'];
450
451 if( isset( $depend['element'] ) && ( isset( $depend['value'] ) && ! empty( $depend['value'] ) ) ){
452
453 unset( $depend['relation'] );
454 unset( $depend['callback'] );
455
456 $field_dependencies[ $depend['element'] ] = array( 'value' => (array)$depend['value'] );
457 }
458
459 }
460
461 if( $field_dependencies ){
462 $this->dependency_list[ $field['id'] ] = $field_dependencies;
463 }
464 }
465
466 /**
467 * Print metafield dependencies
468 *
469 * @return string JSON string containing metafield dependencies
470 */
471 public function print_dependencies(){
472 // echo js dependencies
473 printf( '<script>
474 function auxinCreateNamespace(n){for(var e=n.split("."),a=window,i="",r=e.length,t=0;r>t;t++)"window"!=e[t]&&(i=e[t],a[i]=a[i]||{},a=a[i]);return a;}
475 auxinCreateNamespace("auxin.elements.%3$s");
476 auxin.elements.%3$s.dependencies = %2$s;
477 auxin.elements.%3$s.baseid = "%1$s";</script>',
478 $this->widget_info['base_ID'],
479 wp_json_encode( $this->dependency_list ),
480 $this->defaults[ '__uid' ]
481 );
482 }
483
484
485 /**
486 * Processing widget options on save
487 *
488 * @param array $new_instance The new options
489 * @param array $old_instance The previous options
490 */
491 function update( $new_instance, $old_instance ) {
492 $instance = $old_instance;
493 // TODO: we exclode the defaults because on checkbox there is no this value on unchecked and it replaces with defaults
494 // $new_instance = wp_parse_args( (array) $new_instance, $this->defaults );
495 $new_instance = wp_parse_args( (array) $new_instance );
496 foreach ( $this->fields as $field ) {
497 $id = $field["id"];
498
499 if( ! isset( $new_instance[ $id ] ) ) {
500 continue;
501 }
502
503 if( $field["type"] == "aux_switch" ) {
504 $instance[ $id ] = !empty($new_instance[$id ] ) ? 1 : 0;
505 }
506 if( $field["type"] == "aux_select2_multiple" ) {
507 $instance[ $id ] = esc_sql( $new_instance[ $id ] );
508
509 } else {
510 $instance[ $id ] = is_array( $new_instance[ $id ] ) ? $new_instance[ $id ] : wp_strip_all_tags( $new_instance[ $id ] );
511 }
512
513 }
514
515 return $instance;
516 }
517
518
519 } // end widget class
520
521 endif;
522