get_all_variants() public static method

Returns an array of all available variants.
public static get_all_variants ( ) : array
return array
 /**
  * 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;
 }
Exemplo n.º 2
0
 /**
  * Assets that have to be enqueued in 'customize_controls_enqueue_scripts'.
  */
 public function customize_controls_enqueue_scripts()
 {
     // Get an array of all our fields.
     $fields = Kirki::$fields;
     // Do we have tooltips anywhere?
     $has_tooltips = false;
     foreach ($fields as $field) {
         if ($has_tooltips) {
             continue;
         }
         // Field has tooltip.
         if (isset($field['tooltip']) && !empty($field['tooltip'])) {
             $has_tooltips = true;
         }
         // Backwards-compatibility ("help" argument instead of "tooltip").
         if (isset($field['help']) && !empty($field['help'])) {
             $has_tooltips = true;
         }
     }
     // If we have tooltips, enqueue the tooltips script.
     /* TODO: if ( $has_tooltips ) { */
     wp_enqueue_script('kirki-tooltip', trailingslashit(Kirki::$url) . 'assets/js/tooltip.js', array('jquery', 'customize-controls', 'jquery-ui-tooltip'));
     /* TODO: } */
     // Enqueue the reset script.
     wp_enqueue_script('kirki-reset', trailingslashit(Kirki::$url) . 'assets/js/reset.js', array('jquery', 'kirki-set-setting-value'));
     // Register kirki-functions.
     wp_register_script('kirki-set-setting-value', trailingslashit(Kirki::$url) . 'assets/js/functions/set-setting-value.js');
     wp_register_script('kirki-validate-css-value', trailingslashit(Kirki::$url) . 'assets/js/functions/validate-css-value.js');
     wp_register_script('kirki-notifications', trailingslashit(Kirki::$url) . 'assets/js/functions/notifications.js', array('kirki-l10n', 'kirki-validate-css-value'));
     // Register serialize.js.
     wp_register_script('serialize-js', trailingslashit(Kirki::$url) . 'assets/js/vendor/serialize.js');
     // Register the color-alpha picker.
     wp_enqueue_style('wp-color-picker');
     wp_register_script('wp-color-picker-alpha', trailingslashit(Kirki::$url) . 'assets/js/vendor/wp-color-picker-alpha.js', array('wp-color-picker'), '1.2', true);
     // Register the jquery-ui-spinner.
     wp_register_script('jquery-ui-spinner', trailingslashit(Kirki::$url) . 'assets/js/vendor/jquery-ui-spinner', array('jquery', 'jquery-ui-core', 'jquery-ui-button'));
     // Register codemirror.
     wp_register_script('codemirror', trailingslashit(Kirki::$url) . 'assets/js/vendor/codemirror/lib/codemirror.js', array('jquery'));
     // Register selectize.
     wp_register_script('selectize', trailingslashit(Kirki::$url) . 'assets/js/vendor/selectize.js', array('jquery'));
     // An array of control scripts and their dependencies.
     $scripts = array('checkbox' => array('jquery', 'customize-base'), 'code' => array('jquery', 'customize-base', 'codemirror'), 'color' => array('jquery', 'customize-base', 'wp-color-picker-alpha'), 'color-palette' => array('jquery', 'customize-base', 'jquery-ui-button'), 'dashicons' => array('jquery', 'customize-base'), 'date' => array('jquery', 'customize-base', 'jquery-ui-datepicker'), 'dimension' => array('jquery', 'customize-base', 'kirki-notifications'), 'dropdown-pages' => array('jquery', 'customize-base', 'selectize'), 'editor' => array('jquery', 'customize-base', 'kirki-l10n'), 'generic' => array('jquery', 'customize-base'), 'multicheck' => array('jquery', 'customize-base'), 'multicolor' => array('jquery', 'customize-base', 'wp-color-picker-alpha'), 'number' => array('jquery', 'customize-base', 'jquery-ui-spinner'), 'palette' => array('jquery', 'customize-base', 'jquery-ui-button'), 'preset' => array('jquery', 'customize-base', 'selectize', 'kirki-set-setting-value'), 'radio-buttonset' => array('jquery', 'customize-base'), 'radio-image' => array('jquery', 'customize-base'), 'radio' => array('jquery', 'customize-base'), 'repeater' => array('jquery', 'customize-base', 'jquery-ui-core', 'jquery-ui-sortable', 'kirki-l10n'), 'select' => array('jquery', 'customize-base', 'selectize'), 'slider' => array('jquery', 'customize-base'), 'sortable' => array('jquery', 'customize-base', 'jquery-ui-core', 'jquery-ui-sortable', 'serialize-js'), 'spacing' => array('jquery', 'customize-base', 'kirki-notifications'), 'switch' => array('jquery', 'customize-base'), 'toggle' => array('jquery', 'customize-base'), 'typography' => array('jquery', 'customize-base', 'selectize', 'wp-color-picker-alpha'));
     foreach ($scripts as $id => $dependencies) {
         wp_register_script('kirki-' . $id, trailingslashit(Kirki::$url) . 'assets/js/controls/' . $id . '.js', $dependencies, false, true);
     }
     // Add fonts to our JS objects.
     $google_fonts = Kirki_Fonts::get_google_fonts();
     $standard_fonts = Kirki_Fonts::get_standard_fonts();
     $all_variants = Kirki_Fonts::get_all_variants();
     $all_subsets = Kirki_Fonts::get_google_font_subsets();
     $standard_fonts_final = array();
     foreach ($standard_fonts as $key => $value) {
         $standard_fonts_final[] = array('family' => $value['stack'], 'label' => $value['label'], 'subsets' => array(), 'is_standard' => true, 'variants' => array(array('id' => 'regular', 'label' => $all_variants['regular']), array('id' => 'italic', 'label' => $all_variants['italic']), array('id' => '700', 'label' => $all_variants['700']), array('id' => '700italic', 'label' => $all_variants['700italic'])));
     }
     $google_fonts_final = array();
     foreach ($google_fonts as $family => $args) {
         $label = isset($args['label']) ? $args['label'] : $family;
         $variants = isset($args['variants']) ? $args['variants'] : array('regular', '700');
         $subsets = isset($args['subsets']) ? $args['subsets'] : array();
         $available_variants = array();
         foreach ($variants as $variant) {
             if (array_key_exists($variant, $all_variants)) {
                 $available_variants[] = array('id' => $variant, 'label' => $all_variants[$variant]);
             }
         }
         $available_subsets = array();
         foreach ($subsets as $subset) {
             if (array_key_exists($subset, $all_subsets)) {
                 $available_subsets[] = array('id' => $subset, 'label' => $all_subsets[$subset]);
             }
         }
         $google_fonts_final[] = array('family' => $family, 'label' => $label, 'variants' => $available_variants, 'subsets' => $available_subsets);
     }
     $final = array_merge($standard_fonts_final, $google_fonts_final);
     wp_localize_script('kirki-typography', 'kirkiAllFonts', $final);
 }