/** * Convert a string containing family ID and FVD to CSS properties */ public static function to_css($str) { $object = Youxi_FVD::extract($str); $families = self::get_families(); if (isset($object['id'], $families[$object['id']], $object['font-style'], $object['font-weight'])) { return array('font-family' => $families[$object['id']], 'font-style' => $object['font-style'], 'font-weight' => $object['font-weight']); } return null; }
/** * Get Typekit font families from the current kit */ public static function get_families($humanize = false) { $kit = wp_parse_args((array) self::get_kit(), array('families' => array())); $families = $kit['families']; if (!$humanize) { return $families; } foreach ($families as &$family) { $variations = array(); foreach ($family['variations'] as $variation) { if ($humanized = Youxi_FVD::humanize($variation)) { $variations[$variation] = $humanized; } } $family['variations'] = $variations; } return $families; }
public function render_content($value) { $family_id = ''; $variation = 'n4'; $families = Youxi_Typekit::get_families(); $variations = array(); if ($value = Youxi_FVD::extract($value)) { $family_id = $value['id']; $variation = $value['fvd']; $variations = Youxi_Typekit::get_family_variations($family_id, true); } ?> <div class="youxi-webfont-form-control youxi-webfont-provider-family"> <label class="customize-control-title"><?php esc_html_e('Family', 'youxi'); ?> </label> <select> <option class="placeholder" selected disabled value=""><?php esc_html_e('Select a Font Family', 'youxi'); ?> </option> <?php foreach ((array) $families as $family) { ?> <option value="<?php echo esc_attr($family['id']); ?> "<?php selected($family['id'], $family_id); ?> ><?php echo esc_html($family['name']); ?> </option> <?php } ?> </select> </div> <div class="youxi-webfont-form-control youxi-webfont-provider-variation"<?php if (!$family_id) { echo ' style="display: none;"'; } ?> > <label class="customize-control-title"><?php esc_html_e('Variation', 'youxi'); ?> </label> <select> <?php foreach ((array) $variations as $fvd => $label) { ?> <option value="<?php echo esc_attr($fvd); ?> "<?php selected($fvd, $variation); ?> ><?php echo esc_html($label); ?> </option> <?php } ?> </select> </div> <?php }