/** * Validate the options by type before saving */ function spyropress_validate_setting($value, $type, $field_id, $section) { // check for null if (!$value || !$type || !$field_id) { return $value; } // type = background if ('repeater' == $type) { // skip last dummy element array_pop($value); // reset array indexes array_reindex($value); // Validate Fields $new_values = array(); $total = count($value); for ($i = 0; $i < $total; $i++) { $raw_value = $value[$i]; foreach ($section['fields'] as $field) { if (isset($field['id']) && isset($raw_value[$field['id']]) && !in_array($field['type'], spyropress_exclude_option_types())) { $key = trim($field['id']); $type = $field['type']; $new_value = $raw_value[$key]; $new_values[$i][$key] = spyropress_validate_setting($new_value, $type, $key, $field); } } $new_values[$i] = spyropress_clean_array($new_values[$i]); } $value = $new_values; } elseif ('background' == $type) { $value = spyropress_clean_array($value); if (isset($value['background-color'])) { $value['background-color'] = spyropress_validate_setting($value['background-color'], 'colorpicker', $field_id, $section); } if (isset($value['background-image']) || isset($value['background-pattern'])) { if (isset($value['background-image'])) { $value['background-image'] = spyropress_validate_setting($value['background-image'], 'upload', $field_id, $section); } } } elseif ('typography' == $type) { $value = spyropress_clean_array($value); // if using google fonts unset system fonts if (isset($value['use'])) { unset($value['font-family']); unset($value['font-style']); unset($value['font-weight']); } else { unset($value['font-google']); unset($value['font-google-variant']); } if (isset($value['color'])) { $value['color'] = spyropress_validate_setting($value['color'], 'colorpicker', $field_id, $section); } if (isset($value['font-size']) && $value['font-size'] == '0px') { unset($value['font-size']); } if (isset($value['line-height']) && $value['line-height'] == '0px') { unset($value['line-height']); } if (isset($value['letter-spacing']) && $value['letter-spacing'] == '0px') { unset($value['letter-spacing']); } if (!isset($value['text-shadowcolor']) || $value['text-shadowcolor'] == '') { unset($value['text-hshadow']); unset($value['text-vshadow']); unset($value['text-blur']); unset($value['text-shadowcolor']); } } elseif ('border' == $type) { $heads = array('top', 'right', 'bottom', 'left'); foreach ($heads as $h) { // if empty unset if ($value[$h] == '0px' || empty($value[$h]) || empty($value[$h . '-style']) || empty($value[$h . '-color'])) { unset($value[$h]); unset($value[$h . '-style']); unset($value[$h . '-color']); } else { $value[$h . '-style'] = spyropress_validate_setting($value[$h . '-style'], 'text', $field_id, $section); $value[$h . '-color'] = spyropress_validate_setting($value[$h . '-color'], 'colorpicker', $field_id, $section); } } } elseif ('padder' == $type) { foreach ($value as $k => $v) { if ($v == '0px') { unset($value[$k]); } } } elseif ('colorpicker' == $type) { $value = stripslashes(sanitize_text_field($value)); $value = str_replace('#', '', $value); if (!is_str_starts_with('rgb', $value)) { $value = '#' . $value; } } elseif ('textarea' == $type) { $value = stripslashes($value); } elseif (in_array($type, array('css', 'text', 'editor'))) { $value = stripslashes(wp_kses_post($value)); } elseif (in_array($type, array('upload', 'datepicker', 'hidden', 'range_slider'))) { $value = stripslashes(sanitize_text_field($value)); } return $value; }
<?php $knob_color = stripslashes(sanitize_text_field($knob_color)); $knob_color = str_replace('#', '', $knob_color); if (!is_str_starts_with('rgb', $knob_color)) { $knob_color = '#' . $knob_color; } $plugin_options = array(); $plugin_options['barColor'] = $knob_color; $plugin_options['delay'] = (int) $delay; ?> <div class="circular-bar center"> <div class="circular-bar-chart" data-percent="<?php echo $percentage; ?> " data-plugin-options='<?php echo json_encode($plugin_options); ?> '> <strong><?php echo $title; ?> </strong> <label><span class="percent"><?php echo $percentage; ?> </span>%</label> </div> </div>