/** * Sanitizes the value. * * @access public * @param array $value The value. * @return array */ public function sanitize($value) { // Sanitize each sub-value separately. foreach ($value as $key => $sub_value) { $value[$key] = Kirki_Sanitize_Values::css_dimension($sub_value); } return $value; }
/** * Modifies the value. * * @access protected */ protected function process_value() { $this->value = trim($this->value); // If you use calc() there, I suppose you know what you're doing. // No need to process this any further, just exit. if (false !== strpos($this->value, 'calc')) { return; } // If the value is initial or inherit, we don't need to do anything. // Just exit. if ('initial' == $this->value || 'inherit' == $this->value) { return; } $x_dimensions = array('left', 'center', 'right'); $y_dimensions = array('top', 'center', 'bottom'); // If there's a space, we have an X and a Y value. if (false !== strpos($this->value, ' ')) { $xy = explode(' ', $this->value); $x = trim($xy[0]); $y = trim($xy[1]); // If x is not left/center/right, we need to sanitize it. if (!in_array($x, $x_dimensions)) { $x = Kirki_Sanitize_Values::css_dimension($x); } if (!in_array($y, $y_dimensions)) { $y = Kirki_Sanitize_Values::css_dimension($y); } $this->value = $x . ' ' . $y; return; } $x = 'center'; foreach ($x_dimensions as $x_dimension) { if (false !== strpos($this->value, $x_dimension)) { $x = $x_dimension; } } $y = 'center'; foreach ($y_dimensions as $y_dimension) { if (false !== strpos($this->value, $y_dimension)) { $y = $y_dimension; } } $this->value = $x . ' ' . $y; }
/** * Sanitizes typography controls * * @since 2.2.0 * @param array $value The value. * @return array */ public static function sanitize($value) { if (!is_array($value)) { return array(); } // Escape the font-family. if (isset($value['font-family'])) { $value['font-family'] = esc_attr($value['font-family']); } // Make sure we're using a valid variant. // We're adding checks for font-weight as well for backwards-compatibility // Versions 2.0 - 2.2 were using an integer font-weight. if (isset($value['variant']) || isset($value['font-weight'])) { if (isset($value['font-weight']) && !empty($value['font-weight'])) { if (!isset($value['variant']) || empty($value['variant'])) { $value['variant'] = $value['font-weight']; } unset($value['font-weight']); } $valid_variants = Kirki_Fonts::get_all_variants(); if (!array_key_exists($value['variant'], $valid_variants)) { $value['variant'] = 'regular'; } } // Make sure the saved value is "subsets" (plural) and not "subset". // This is for compatibility with older versions. if (isset($value['subset'])) { if (!empty($value['subset'])) { if (!isset($value['subsets']) || empty($value['subset'])) { $value['subsets'] = $value['subset']; } } unset($value['subset']); } // Make sure we're using a valid subset. if (isset($value['subsets'])) { $valid_subsets = Kirki_Fonts::get_google_font_subsets(); $subsets_ok = array(); if (is_array($value['subsets'])) { foreach ($value['subsets'] as $subset) { if (array_key_exists($subset, $valid_subsets)) { $subsets_ok[] = $subset; } } $value['subsets'] = $subsets_ok; } } // Sanitize the font-size. if (isset($value['font-size']) && !empty($value['font-size'])) { $value['font-size'] = Kirki_Sanitize_Values::css_dimension($value['font-size']); if (is_numeric($value['font-size'])) { $value['font-size'] .= 'px'; } } // Sanitize the line-height. if (isset($value['line-height']) && !empty($value['line-height'])) { $value['line-height'] = Kirki_Sanitize_Values::css_dimension($value['line-height']); } // Sanitize the letter-spacing. if (isset($value['letter-spacing']) && !empty($value['letter-spacing'])) { $value['letter-spacing'] = Kirki_Sanitize_Values::css_dimension($value['letter-spacing']); if (is_numeric($value['letter-spacing'])) { $value['letter-spacing'] .= 'px'; } } // Sanitize the text-align. if (isset($value['text-align']) && !empty($value['text-align'])) { if (!in_array($value['text-align'], array('inherit', 'left', 'center', 'right', 'justify'))) { $value['text-align'] = 'inherit'; } } // Sanitize the text-transform. if (isset($value['text-transform']) && !empty($value['text-transform'])) { if (!in_array($value['text-transform'], array('none', 'capitalize', 'uppercase', 'lowercase', 'initial', 'inherit'))) { $value['text-transform'] = 'none'; } } // Sanitize the color. if (isset($value['color']) && !empty($value['color'])) { $color = ariColor::newColor($value['color']); $value['color'] = $color->toCSS('hex'); } return $value; }