PluginProbe ʕ •ᴥ•ʔ
PiWeb Product Enquiry or product catalog for WooCommerce / 2.2.33.34
PiWeb Product Enquiry or product catalog for WooCommerce v2.2.33.34
2.2.34.43 2.2.34.42 2.2.34.41 2.2.34.40 2.2.34.39 trunk 2.2.22 2.2.26 2.2.33.16 2.2.33.17 2.2.33.19 2.2.33.20 2.2.33.21 2.2.33.22 2.2.33.23 2.2.33.24 2.2.33.26 2.2.33.27 2.2.33.29 2.2.33.30 2.2.33.31 2.2.33.32 2.2.33.33 2.2.33.34 2.2.33.36 2.2.33.37 2.2.33.39 2.2.33.40 2.2.33.41 2.2.33.42 2.2.33.43 2.2.33.44 2.2.33.46 2.2.33.47 2.2.33.49 2.2.34.0 2.2.34.1 2.2.34.10 2.2.34.11 2.2.34.12 2.2.34.13 2.2.34.14 2.2.34.16 2.2.34.17 2.2.34.19 2.2.34.2 2.2.34.20 2.2.34.21 2.2.34.22 2.2.34.23 2.2.34.24 2.2.34.26 2.2.34.27 2.2.34.29 2.2.34.3 2.2.34.30 2.2.34.31 2.2.34.32 2.2.34.33 2.2.34.34 2.2.34.36 2.2.34.37 2.2.34.4 2.2.34.6 2.2.34.7 2.2.34.9
enquiry-quotation-for-woocommerce / includes / pisol.class.form.php
enquiry-quotation-for-woocommerce / includes Last commit date
background.png 1 year ago banner-sample.php 1 year ago class-pisol-enquiry-quotation-woocommerce-activator.php 1 year ago class-pisol-enquiry-quotation-woocommerce-deactivator.php 1 year ago class-pisol-enquiry-quotation-woocommerce-i18n.php 1 year ago class-pisol-enquiry-quotation-woocommerce-loader.php 1 year ago class-pisol-enquiry-quotation-woocommerce.php 1 year ago conflict-fixer.php 1 year ago includes.php 1 year ago index.php 1 year ago pisol.class.form.php 1 year ago pisol.class.promotion.php 1 year ago review-icon.svg 1 year ago review.php 1 year ago
pisol.class.form.php
610 lines
1 <?php
2 /**
3 * version 3.10
4 * work with bootstrap
5 */
6 defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
7
8 if(!class_exists('pisol_class_form_eqw')):
9 class pisol_class_form_eqw{
10
11 private $setting;
12 private $saved_value;
13 private $pro;
14 public $allowed_tags;
15 public $allowed_atts;
16
17 function __construct($setting){
18
19 $this->setting = $setting;
20
21 if(isset( $this->setting['default'] )){
22 $this->saved_value = get_option($this->setting['field'], $this->setting['default']);
23 }else{
24 $this->saved_value = get_option($this->setting['field']);
25 }
26
27 if(isset( $this->setting['pro'] )){
28 if($this->setting['pro']){
29 $this->pro = ' free-version ';
30 //$this->setting['desc'] = '<span style="color:#f00; font-weight:bold;">Workes in Pro version only / Without PRO version this setting will have no effect</span>';
31 }else{
32 $this->pro = ' paid-version ';
33 }
34 }else{
35 $this->pro = "";
36 }
37
38 $allowed_atts = array(
39 'align' => array(),
40 'class' => array(),
41 'selected' => array(),
42 'multiple' => array(),
43 'checked' => array(),
44 'type' => array(),
45 'id' => array(),
46 'dir' => array(),
47 'lang' => array(),
48 'style' => array(),
49 'xml:lang' => array(),
50 'src' => array(),
51 'alt' => array(),
52 'href' => array(),
53 'rel' => array(),
54 'rev' => array(),
55 'target' => array(),
56 'novalidate' => array(),
57 'type' => array(),
58 'value' => array(),
59 'name' => array(),
60 'tabindex' => array(),
61 'action' => array(),
62 'method' => array(),
63 'for' => array(),
64 'width' => array(),
65 'height' => array(),
66 'data' => array(),
67 'title' => array(),
68 'min' => array(),
69 'max' => array(),
70 'step' => array(),
71 'required' => array(),
72 'readonly' => array(),
73 );
74 $this->allowed_tags['form'] = $allowed_atts;
75 $this->allowed_tags['br'] = $allowed_atts;
76 $this->allowed_tags['label'] = $allowed_atts;
77 $this->allowed_tags['input'] = $allowed_atts;
78 $this->allowed_tags['select'] = $allowed_atts;
79 $this->allowed_tags['option'] = $allowed_atts;
80 $this->allowed_tags['textarea'] = $allowed_atts;
81 $this->allowed_tags['iframe'] = $allowed_atts;
82 $this->allowed_tags['script'] = $allowed_atts;
83 $this->allowed_tags['style'] = $allowed_atts;
84 $this->allowed_tags['strong'] = $allowed_atts;
85 $this->allowed_tags['small'] = $allowed_atts;
86 $this->allowed_tags['table'] = $allowed_atts;
87 $this->allowed_tags['span'] = $allowed_atts;
88 $this->allowed_tags['abbr'] = $allowed_atts;
89 $this->allowed_tags['code'] = $allowed_atts;
90 $this->allowed_tags['pre'] = $allowed_atts;
91 $this->allowed_tags['div'] = $allowed_atts;
92 $this->allowed_tags['img'] = $allowed_atts;
93 $this->allowed_tags['h1'] = $allowed_atts;
94 $this->allowed_tags['h2'] = $allowed_atts;
95 $this->allowed_tags['h3'] = $allowed_atts;
96 $this->allowed_tags['h4'] = $allowed_atts;
97 $this->allowed_tags['h5'] = $allowed_atts;
98 $this->allowed_tags['h6'] = $allowed_atts;
99 $this->allowed_tags['ol'] = $allowed_atts;
100 $this->allowed_tags['ul'] = $allowed_atts;
101 $this->allowed_tags['li'] = $allowed_atts;
102 $this->allowed_tags['em'] = $allowed_atts;
103 $this->allowed_tags['hr'] = $allowed_atts;
104 $this->allowed_tags['br'] = $allowed_atts;
105 $this->allowed_tags['tr'] = $allowed_atts;
106 $this->allowed_tags['td'] = $allowed_atts;
107 $this->allowed_tags['p'] = $allowed_atts;
108 $this->allowed_tags['a'] = $allowed_atts;
109 $this->allowed_tags['b'] = $allowed_atts;
110 $this->allowed_tags['i'] = $allowed_atts;
111
112
113 $this->check_field_type();
114 }
115
116 function check_field_type(){
117 if(isset($this->setting['type'])):
118 switch ($this->setting['type']){
119 case 'select':
120 $this->select_box();
121 break;
122
123 case 'number':
124 $this->number_box();
125 break;
126
127 case 'text':
128 $this->text_box();
129 break;
130
131 case 'text_html':
132 $this->text_box();
133 break;
134
135 case 'textarea':
136 $this->textarea_box();
137 break;
138
139 case 'multiselect':
140 $this->multiselect_box();
141 break;
142
143 case 'color':
144 $this->color_box();
145 break;
146
147 case 'hidden':
148 $this->hidden_box();
149 break;
150
151 case 'switch':
152 $this->switch_display();
153 break;
154
155 case 'switch_category':
156 $this->switch_category_display();
157 break;
158
159 case 'setting_category':
160 $this->setting_category();
161 break;
162
163 case 'image':
164 $this->image();
165 break;
166 }
167 endif;
168 }
169
170 function bootstrap($label, $field, $desc = "", $links = "", $title_col = 5){
171 $setting_col = 12 - $title_col;
172 if($this->setting['type'] != 'hidden'){
173 ?>
174 <div id="row_<?php echo esc_attr($this->setting['field']); ?>" class="row py-4 border-bottom align-items-center <?php echo esc_attr($this->pro); ?> <?php echo !empty($this->setting['class']) ? esc_attr($this->setting['class']) : ''; ?>">
175 <div class="col-12 col-md-<?php echo esc_attr($title_col); ?>">
176 <?php echo wp_kses($label, $this->allowed_tags); ?>
177 <?php echo wp_kses($desc != "" ? $desc.'<br>': "", $this->allowed_tags); ?>
178 <?php echo wp_kses($links != "" ? $links: "", $this->allowed_tags); ?>
179 </div>
180 <div class="col-12 col-md-<?php echo esc_attr($setting_col); ?>">
181 <?php echo wp_kses($field, $this->allowed_tags); ?>
182 </div>
183 </div>
184 <?php
185 }else{
186 ?>
187 <div id="row_<?php echo esc_attr($this->setting['field']); ?>" class="row align-items-center <?php echo esc_attr($this->pro); ?>">
188 <div class="col-12 col-md-12">
189 <?php echo wp_kses($field, $this->allowed_tags); ?>
190 </div>
191 </div>
192 <?php
193 }
194 }
195
196
197 function bootstrap_switch_category($label, $field, $desc = "", $links = ""){
198 ?>
199 <div id="row_<?php echo esc_attr($this->setting['field']); ?>" class="row py-4 border-bottom align-items-center <?php echo ( isset($this->setting['class']) ? esc_attr($this->setting['class']) : "" ); ?>">
200 <div class="col-9">
201 <?php echo wp_kses($label, $this->allowed_tags) ; ?>
202 <?php echo wp_kses($desc != "" ? $desc.'<br>': "", $this->allowed_tags); ?>
203 <?php echo wp_kses($links != "" ? $links: "", $this->allowed_tags); ?>
204 </div>
205 <div class="col-3">
206 <?php echo wp_kses($field, $this->allowed_tags); ?>
207 </div>
208 </div>
209 <?php
210 }
211
212 /*
213 Field type: select box
214 */
215 function select_box(){
216
217 $label = '<label class="h6 mb-0" for="'.esc_attr($this->setting['field']).'">'.wp_kses_post($this->setting['label']).'</label>';
218 $desc = (isset($this->setting['desc'])) ? '<br><small>'.wp_kses($this->setting['desc'], $this->allowed_tags).'</small>' : "";
219
220 $field = '<select class="form-control '.esc_attr($this->pro).'" name="'.esc_attr($this->setting['field']).'" id="'.esc_attr($this->setting['field']).'"'
221 .(isset($this->setting['multiple']) ? ' multiple="'.esc_attr($this->setting['multiple']).'"': '')
222 .'>';
223 foreach($this->setting['value'] as $key => $val){
224 $field .= '<option value="'.esc_attr($key).'" '.( ( $this->saved_value == $key) ? " selected=\"selected\" " : "" ).'>'.esc_html($val).'</option>';
225 }
226 $field .= '</select>';
227
228 $links = $this->generateLinks($this->setting);
229
230 $this->bootstrap($label, $field, $desc, $links, 7);
231
232 }
233
234 function generateLinks($setting){
235 /*
236 'links'=>array(array('name'=>"Video", 'url'=>"https://www.youtube.com/watch?v=KNC5lkoE2Fs", 'type'=>'iframe'))
237 'links'=>array(array('name'=>"Video", 'url'=>"image url", 'type'=>'image'))
238 */
239
240 if(!isset($setting['links']) || !is_array($setting['links']) || empty($setting['links'])) return;
241
242 $html = '';
243 $links = $setting['links'];
244 foreach($links as $link){
245 $class = 'pi-'.$link['type'];
246 $html .= '<a href="'.esc_url($link['url']).'" class="'.esc_attr($class).' pi-info-links" target="_blank">'.esc_html($link['name']).'</a> ';
247 }
248 return $html;
249 }
250
251 /*
252 Field type: select box
253 */
254 function multiselect_box(){
255 $label = '<label class="h6 mb-0" for="'.esc_attr($this->setting['field']).'">'.wp_kses_post($this->setting['label']).'</label>';
256 $desc = ((isset($this->setting['desc'])) ? '<br><small>'.wp_kses($this->setting['desc'], $this->allowed_tags).'</small>' : "");
257 $field = '<select style="min-height:100px;" class="form-control multiselect '.esc_attr($this->pro).'" name="'.esc_attr($this->setting['field']).'[]" id="'.esc_attr($this->setting['field']).'" multiple'. '>';
258 foreach($this->setting['value'] as $key => $val){
259 if(isset($this->saved_value) && $this->saved_value != false){
260 $field .='<option value="'.esc_attr($key).'" '.( ( in_array($key, $this->saved_value) ) ? " selected=\"selected\" " : "" ).'>'.esc_html($val).'</option>';
261 }else{
262 $field .= '<option value="'.esc_attr($key).'">'.esc_html($val).'</option>';
263 }
264 }
265 $field .= '</select>';
266
267 $links = $this->generateLinks($this->setting);
268
269 $this->bootstrap($label, $field, $desc, $links);
270
271 }
272
273 /*
274 Field type: Number box
275 */
276 function number_box(){
277
278 $label = '<label class="h6 mb-0" for="'.esc_attr($this->setting['field']).'">'.wp_kses_post($this->setting['label']).'</label>';
279 $desc = (isset($this->setting['desc'])) ? '<br><small>'.wp_kses($this->setting['desc'], $this->allowed_tags).'</small>' : "";
280 $field = '<input type="number" class="form-control '.esc_attr($this->pro).'" name="'.esc_attr($this->setting['field']).'" id="'.esc_attr($this->setting['field']).'" value="'.esc_attr($this->saved_value).'"'
281 .(isset($this->setting['min']) ? ' min="'.esc_attr($this->setting['min']).'"': '')
282 .(isset($this->setting['max']) ? ' max="'.esc_attr($this->setting['max']).'"': '')
283 .(isset($this->setting['step']) ? ' step="'.esc_attr($this->setting['step']).'"': '')
284 .(isset($this->setting['required']) ? ' required="'.esc_attr($this->setting['required']).'"': '')
285 .(isset($this->setting['readonly']) ? ' readonly="'.esc_attr($this->setting['readonly']).'"': '')
286 .'>';
287
288 $links = $this->generateLinks($this->setting);
289
290 $this->bootstrap($label, $field, $desc, $links, 7);
291 }
292
293 /*
294 Field type: Number box
295 */
296 function text_box(){
297
298 $label = '<label class="h6 mb-0" for="'.esc_attr($this->setting['field']).'">'.wp_kses_post($this->setting['label']).'</label>';
299 $desc = (isset($this->setting['desc'])) ? '<br><small>'.wp_kses($this->setting['desc'], $this->allowed_tags).'</small>' : "";
300 $field = '<input type="text" class="form-control '.esc_attr($this->pro).'" name="'.esc_attr($this->setting['field']).'" id="'.esc_attr($this->setting['field']).'" value="'.esc_attr($this->saved_value).'"'
301 .(isset($this->setting['required']) ? ' required="'.esc_attr($this->setting['required']).'"': '')
302 .(isset($this->setting['readonly']) ? ' readonly="'.esc_attr($this->setting['readonly']).'"': '')
303 .'>';
304
305 $links = $this->generateLinks($this->setting);
306
307 $this->bootstrap($label, $field, $desc, $links, 7);
308 }
309
310 /*
311 Textarea field
312 */
313 function textarea_box(){
314 $label = '<label class="h6 mb-0" for="'.esc_attr($this->setting['field']).'">'.wp_kses_post($this->setting['label']).'</label>';
315 $desc = (isset($this->setting['desc'])) ? '<br><small>'.wp_kses($this->setting['desc'], $this->allowed_tags).'</small>' : "";
316 $field = '<textarea style="height:auto !important; min-height:200px;" type="text" class="form-control '.esc_attr($this->pro).'" name="'.esc_attr($this->setting['field']).'" id="'.esc_attr($this->setting['field']).'"'
317 .(isset($this->setting['required']) ? ' required="'.esc_attr($this->setting['required']).'"': '')
318 .(isset($this->setting['readonly']) ? ' readonly="'.esc_attr($this->setting['readonly']).'"': '')
319 .'>';
320 $field .= esc_textarea($this->saved_value);
321 $field .= '</textarea>';
322
323 $links = $this->generateLinks($this->setting);
324
325 $this->bootstrap($label, $field, $desc, $links, 12);
326 }
327
328 /*
329 Field type: color
330 */
331 function color_box(){
332 wp_enqueue_style( 'wp-color-picker');
333 wp_enqueue_script( 'wp-color-picker');
334 wp_add_inline_script('wp-color-picker','
335 jQuery(document).ready(function($) {
336 $(".color-picker").wpColorPicker();
337 });
338 ');
339 $label = '<label class="h6 mb-0" for="'.esc_attr($this->setting['field']).'">'.wp_kses_post($this->setting['label']).'</label>';
340 $desc = (isset($this->setting['desc'])) ? '<br><small>'.wp_kses($this->setting['desc'], $this->allowed_tags).'</small>' : "";
341 $field = '<input type="text" class="color-picker pisol_select '.esc_attr($this->pro).'" name="'.esc_attr($this->setting['field']).'" id="'.esc_attr($this->setting['field']).'" value="'.esc_attr($this->saved_value).'"'
342 .(isset($this->setting['required']) ? ' required="'.esc_attr($this->setting['required']).'"': '')
343 .(isset($this->setting['readonly']) ? ' readonly="'.esc_attr($this->setting['readonly']).'"': '')
344 .'>';
345
346 $links = $this->generateLinks($this->setting);
347
348 $this->bootstrap($label, $field, $desc, $links, 6);
349 }
350
351 function hidden_box(){
352 $label = '<label class="h6 mb-0" for="'.esc_attr($this->setting['field']).'">'.wp_kses_post($this->setting['label']).'</label>';
353 $desc = (isset($this->setting['desc'])) ? '<br><small>'.wp_kses($this->setting['desc'], $this->allowed_tags).'</small>' : "";
354 $field ='<input type="hidden" class="pisol_select '.esc_attr($this->pro).'" name="'.esc_attr($this->setting['field']).'" id="'.esc_attr($this->setting['field']).'" value="'.esc_attr($this->saved_value).'"'
355 .(isset($this->setting['required']) ? ' required="'.esc_attr($this->setting['required']).'"': '')
356 .(isset($this->setting['readonly']) ? ' readonly="'.esc_attr($this->setting['readonly']).'"': '')
357 .'>';
358
359 $links = $this->generateLinks($this->setting);
360
361 $this->bootstrap($label, $field, $desc, $links);
362 }
363
364 /*
365 Field type: switch
366 */
367 function switch_display(){
368
369 $label = '<label class="h6 mb-0" for="'.esc_attr($this->setting['field']).'">'.wp_kses_post($this->setting['label']).'</label>';
370 $desc = (isset($this->setting['desc'])) ? '<br><small>'.wp_kses($this->setting['desc'], $this->allowed_tags).'</small>' : "";
371
372 $field = '<div class="custom-control custom-switch">
373 <input type="checkbox" value="1" class="custom-control-input" name="'.esc_attr($this->setting['field']).'" id="'.esc_attr($this->setting['field']).'" '.(($this->saved_value == true) ? "checked='checked'": "").' >
374 <label class="custom-control-label" for="'.esc_attr($this->setting['field']).'"></label>
375 </div>';
376
377 $links = $this->generateLinks($this->setting);
378
379 $this->bootstrap($label, $field, $desc, $links, 9);
380 }
381
382 function switch_category_display(){
383
384 $label = '<label class="h6 mb-0" for="'.esc_attr($this->setting['field']).'">'.wp_kses_post($this->setting['label']).'</label>';
385 $desc = (isset($this->setting['desc'])) ? '<br><small>'.wp_kses($this->setting['desc'], $this->allowed_tags).'</small>' : "";
386
387 $field = '<div class="custom-control custom-switch">
388 <input type="checkbox" value="1" class="custom-control-input" name="'.esc_attr($this->setting['field']).'" id="'.esc_attr($this->setting['field']).'" '.(!empty($this->saved_value) ? "checked='checked'": "").' >
389 <label class="custom-control-label" for="'.esc_attr($this->setting['field']).'"></label>
390 </div>';
391
392 $links = $this->generateLinks($this->setting);
393
394 $this->bootstrap_switch_category($label, $field, $desc, $links);
395 }
396
397 /**
398 * Category: is to devide setting in different part
399 */
400 function setting_category(){
401 if(isset($this->setting['label']) && $this->setting['label'] != ""):
402 ?>
403 <div id="row_<?php echo esc_attr($this->setting['field']); ?>" class="row py-4 border-bottom align-items-center <?php echo ( isset($this->setting['class']) ? esc_attr($this->setting['class']) : "" ); ?>">
404 <div class="col-12">
405 <h2 class="mt-0 mb-0 <?php echo ( isset($this->setting['class_title']) ? esc_attr($this->setting['class_title']) : "" ); ?>"><?php echo wp_kses_post($this->setting['label']); ?></h2>
406 </div>
407 </div>
408 <?php
409 endif;
410 }
411
412 function image(){
413 wp_enqueue_media();
414 add_action( 'admin_footer', array($this,'media_selector_scripts') );
415 $label = '<label class="h6 mb-0" for="'.esc_attr($this->setting['field']).'">'.wp_kses_post($this->setting['label']).'</label>';
416 $desc = (isset($this->setting['desc'])) ? '<br><small>'.wp_kses($this->setting['desc'], $this->allowed_tags).'</small>' : "";
417 $field = '
418 <div class="row align-items-center">
419 <div class="col-6">
420 <input id="'.esc_attr($this->setting['field']).'_button" type="button" class="button" value="'.esc_attr(__('Upload image','add-coupon-by-link-woocommerce')).'" />
421 <input type="hidden" name="'.esc_attr($this->setting['field']).'" id="'.esc_attr($this->setting['field']).'" value="'.esc_attr($this->saved_value).'">
422 </div>
423 <div class="col-6">
424 <div class="image-preview-wrapper">
425 <img id="'.esc_attr($this->setting['field']).'_preview" '.($this->saved_value > 0 ? 'src="'.wp_get_attachment_url( get_option( $this->setting['field'] ) ).'"': '').' width="100" height="100" style="max-height: 100px; width: 100px;">
426 <a href="javascript:void(0)" class="clear-image-'.esc_attr($this->setting['field']).'">Clear</a>
427 </div>
428 </div>
429 </div>
430 ';
431 $links = $this->generateLinks($this->setting);
432
433 $this->bootstrap($label, $field, $desc, $links);
434 }
435
436 function media_selector_scripts(){
437 $my_saved_attachment_post_id = get_option($this->setting['field'], 0 );
438 ?><script type='text/javascript'>
439 jQuery( document ).ready( function( $ ) {
440 // Uploading files
441 var file_frame;
442 var wp_media_post_id = wp.media.model.settings.post.id; // Store the old id
443 var set_to_post_id = <?php echo esc_attr($my_saved_attachment_post_id == 0 || $my_saved_attachment_post_id =="" ? "0" : $my_saved_attachment_post_id) ; ?>; // Set this
444 jQuery('#<?php echo esc_attr($this->setting['field']); ?>_button').on('click', function( event ){
445 event.preventDefault();
446 // If the media frame already exists, reopen it.
447 if ( file_frame ) {
448 // Set the post ID to what we want
449 file_frame.uploader.uploader.param( 'post_id', set_to_post_id );
450 // Open frame
451 file_frame.open();
452 return;
453 } else {
454 // Set the wp.media post id so the uploader grabs the ID we want when initialised
455 wp.media.model.settings.post.id = set_to_post_id;
456 }
457 // Create the media frame.
458 file_frame = wp.media.frames.file_frame = wp.media({
459 title: 'Select a image to upload',
460 button: {
461 text: 'Use this image',
462 },
463 multiple: false // Set to true to allow multiple files to be selected
464 });
465 // When an image is selected, run a callback.
466 file_frame.on( 'select', function() {
467 // We set multiple to false so only get one image from the uploader
468 attachment = file_frame.state().get('selection').first().toJSON();
469 // Do something with attachment.id and/or attachment.url here
470 $( '#<?php echo esc_attr($this->setting['field']); ?>_preview' ).attr( 'src', attachment.url ).css( 'width', 'auto' );
471 $( '#<?php echo esc_attr($this->setting['field']); ?>' ).val( attachment.id );
472 // Restore the main post ID
473 wp.media.model.settings.post.id = wp_media_post_id;
474 });
475 // Finally, open the modal
476 file_frame.open();
477 });
478 // Restore the main ID when the add media button is pressed
479 jQuery( 'a.add_media' ).on( 'click', function() {
480 wp.media.model.settings.post.id = wp_media_post_id;
481 });
482 jQuery( 'a.clear-image-<?php echo esc_attr($this->setting['field']); ?>' ).on( 'click', function() {
483 $( '#<?php echo esc_attr($this->setting['field']); ?>_preview' ).attr("src","");
484 $( '#<?php echo esc_attr($this->setting['field']); ?>' ).val("");
485 });
486 });
487 </script>
488 <?php
489 }
490
491
492 /**
493 * if a field don't want to do any sanitization then they will set
494 * 'validation' => false
495 * and if they want to add there custom sanitization function then they will do
496 * 'sanitize_callback' => 'function_name' OR
497 * 'sanitize_callback' => array('class_name', 'function_name')
498 * if they want to use different sanitization function that is other then the one defined for them then they will use
499 * 'sanitize_callback' => 'sanitize_text_field' => directly add the sanitization function name
500 */
501 static function register_setting($group, $setting){
502
503 $validation_function = self::getValidationFunction($setting);
504
505
506 if($validation_function !== false){
507 if(!is_array($validation_function) && method_exists(__CLASS__, $validation_function)){
508 register_setting($group, $setting['field'], [
509 'sanitize_callback' => [__CLASS__, $validation_function]
510 ]);
511 return;
512 }else{
513 if(is_array($validation_function) && count($validation_function) == 2 && method_exists($validation_function[0], $validation_function[1])){
514 register_setting($group, $setting['field'], [
515 'sanitize_callback' => $validation_function
516 ]);
517 return;
518 }elseif(!is_array($validation_function) && function_exists($validation_function)){
519 register_setting($group, $setting['field'], [
520 'sanitize_callback' => $validation_function
521 ]);
522 return;
523 }
524 }
525 }
526
527 register_setting($group, $setting['field']);
528
529 }
530
531 static function getValidationFunction($setting){
532 if(isset($setting['validation']) && $setting['validation'] === false) return false;
533
534 if(isset($setting['sanitize_callback'])){
535 return $setting['sanitize_callback'];
536 }
537
538 $sanitize_text_allow_basic_html_field_types = ['text_html'];
539
540 $sanitize_text_field_types = ['select', 'text', 'multiselect', 'color', 'hidden', 'switch', 'switch_category'];
541
542 $sanitize_textarea_field_types = ['textarea'];
543
544 $sanitize_number_field_types = ['number'];
545
546 if(isset($setting['type']) && in_array($setting['type'], $sanitize_text_field_types)){
547 return 'sanitize_text_field';
548 }
549
550 if(isset($setting['type']) && in_array($setting['type'], $sanitize_textarea_field_types)){
551 return 'sanitize_textarea_field';
552 }
553
554 if(isset($setting['type']) && in_array($setting['type'], $sanitize_number_field_types)){
555 return 'sanitize_numeric_values';
556 }
557
558 if(isset($setting['type']) && in_array($setting['type'], $sanitize_text_allow_basic_html_field_types)){
559 return 'sanitize_text_allow_basic_html';
560 }
561
562 return false;
563
564 }
565
566 static function sanitize_text_field($input) {
567
568 $sanitized_input = is_array($input) ? array_map([__CLASS__,'sanitize_text_field'], $input) : sanitize_text_field($input);
569
570 return $sanitized_input;
571 }
572
573 static function sanitize_textarea_field($input) {
574 $sanitized_input = sanitize_textarea_field($input);
575
576 return $sanitized_input;
577
578 }
579
580 static function sanitize_text_allow_basic_html($input) {
581 $allowed_tags = array(
582 'span' => array(),
583 'strong' => array(),
584 'b' => array(),
585 'i' => array(),
586 'br' => array(),
587 );
588
589 $sanitized_input = wp_kses($input, $allowed_tags);
590
591 return $sanitized_input;
592 }
593
594 // Sanitize numeric input (supports both integer and float)
595 static function sanitize_numeric_values($input) {
596 if (is_numeric($input)) {
597 if (ctype_digit($input)) {
598 $sanitized_input = intval($input);
599 } else {
600 $sanitized_input = floatval($input);
601 }
602 } else {
603 $sanitized_input = 0; // You can change this to any default value
604 }
605
606 return $sanitized_input;
607 }
608
609 }
610 endif;