public function to_json() { parent::to_json(); $this->json['choices'] = array(); if (is_array($this->choices)) { if (isset($this->choices['top']) && true == $this->choices['top']) { $this->json['choices']['top'] = true; } if (isset($this->choices['bottom']) && true == $this->choices['bottom']) { $this->json['choices']['bottom'] = true; } if (isset($this->choices['left']) && true == $this->choices['left']) { $this->json['choices']['left'] = true; } if (isset($this->choices['right']) && true == $this->choices['right']) { $this->json['choices']['right'] = true; } } $i18n = Kirki_Toolkit::i18n(); $this->json['l10n'] = array('top' => $i18n['top'], 'bottom' => $i18n['bottom'], 'left' => $i18n['left'], 'right' => $i18n['right']); if (isset($this->json['choices']['top']) && !isset($this->json['value']['top'])) { $this->json['value']['top'] = $this->json['default']['top']; } if (isset($this->json['choices']['bottom']) && !isset($this->json['value']['bottom'])) { $this->json['value']['bottom'] = $this->json['default']['bottom']; } if (isset($this->json['choices']['left']) && !isset($this->json['value']['left'])) { $this->json['value']['left'] = $this->json['default']['left']; } if (isset($this->json['choices']['right']) && !isset($this->json['value']['top'])) { $this->json['value']['right'] = $this->json['default']['right']; } }
/** * Access the single instance of this class * @return Kirki */ public static function get_instance() { if (null == self::$instance) { self::$instance = new Kirki_Toolkit(); } return self::$instance; }
/** * Access the single instance of this class. * * @static * @access public * @return object Kirki_Toolkit. */ public static function get_instance() { if (null === self::$instance) { self::$instance = new self(); } return self::$instance; }
public function to_json() { parent::to_json(); $this->json['choices'] = is_array($this->choices) ? array('top' => in_array('top', $this->choices) ? true : false, 'bottom' => in_array('bottom', $this->choices) ? true : false, 'left' => in_array('left', $this->choices) ? true : false, 'right' => in_array('right', $this->choices) ? true : false, 'units' => isset($this->choices['units']) ? $this->choices['units'] : false) : array(); $i18n = Kirki_Toolkit::i18n(); $this->json['l10n'] = array('top' => $i18n['top'], 'bottom' => $i18n['bottom'], 'left' => $i18n['left'], 'right' => $i18n['right']); }
/** * Returns the Kirki object */ function Kirki() { // Make sure the class is instanciated $kirki = Kirki_Toolkit::get_instance(); // The path of the current Kirki instance Kirki::$path = dirname(__FILE__); return $kirki; }
public function to_json() { parent::to_json(); $i18n = Kirki_Toolkit::i18n(); $this->json['choices'] = empty($this->choices) || !is_array($this->choices) ? array() : $this->choices; $this->json['choices']['on'] = isset($this->choices['on']) ? $this->choices['on'] : $i18n['on']; $this->json['choices']['off'] = isset($this->choices['off']) ? $this->choices['off'] : $i18n['off']; $this->json['choices']['round'] = isset($this->choices['round']) ? $this->choices['round'] : false; }
public function to_json() { parent::to_json(); $i18n = Kirki_Toolkit::i18n(); $this->json['fonts'] = $this->get_all_fonts(); $value = $this->value(); $this->json['value'] = array('bold' => isset($value['bold']) ? $value['bold'] : false, 'italic' => isset($value['italic']) ? $value['italic'] : false, 'underline' => isset($value['underline']) ? $value['underline'] : false, 'strikethrough' => isset($value['strikethrough']) ? $value['strikethrough'] : false, 'font-family' => isset($value['font-family']) ? $value['font-family'] : '', 'font-size' => isset($value['font-size']) ? $value['font-size'] : '', 'font-weight' => isset($value['font-weight']) ? $value['font-weight'] : '', 'line-height' => isset($value['line-height']) ? $value['line-height'] : '', 'letter-spacing' => isset($value['letter-spacing']) ? $value['letter-spacing'] : '', 'color' => isset($value['color']) ? $value['color'] : ''); $this->json['l10n'] = array('font-family' => $i18n['font-family'], 'font-size' => $i18n['font-size'], 'font-weight' => $i18n['font-weight'], 'line-height' => $i18n['line-height'], 'letter-spacing' => $i18n['letter-spacing'], 'color' => $i18n['color']); }
/** * Returns the Kirki object */ function Kirki() { // Make sure the class is instanciated $kirki = Kirki_Toolkit::get_instance(); $kirki->font_registry = new Kirki_Fonts_Font_Registry(); $kirki->scripts = new Kirki_Scripts_Registry(); $kirki->api = new Kirki(); $kirki->styles = array('back' => new Kirki_Styles_Customizer(), 'front' => new Kirki_Styles_Frontend()); return $kirki; }
/** * Helper that enqueues a script for a control. * * Every Kirki Control should use this function to enqueue * its main JS file (not dependencies like jQuery or jQuery UI). * * These files are only enqueued when debugging Kirki * * @param string $handle * @param string $file * @param array $deps */ public static function enqueue_customizer_control_script($handle, $file = null, $deps = array(), $in_footer = false) { if (false !== strpos($file, 'controls/') && Kirki_Toolkit::kirki_debug() || false === strpos($file, 'controls/')) { $file = trailingslashit(Kirki::$url) . 'assets/js/' . $file . '.js'; foreach ($deps as $dep) { wp_enqueue_script($dep); } // We are debugging, no need of version or suffix wp_enqueue_script($handle, $file, $deps, '', $in_footer); } }
public function to_json() { parent::to_json(); $i18n = Kirki_Toolkit::i18n(); $this->choices = empty($this->choices) || !is_array($this->choices) ? array() : $this->choices; $this->choices['on'] = isset($this->choices['on']) ? $this->choices['on'] : $i18n['on']; $this->choices['off'] = isset($this->choices['off']) ? $this->choices['off'] : $i18n['off']; $this->json['id'] = $this->id; $this->json['value'] = $this->value(); $this->json['choices'] = $this->choices; $this->json['link'] = $this->get_link(); }
public function test_kirki_fonts() { $this->assertEquals(Kirki_Fonts::get_all_fonts(), Kirki_Toolkit::fonts()->get_all_fonts()); $this->assertEquals(Kirki_Fonts::get_font_choices(), Kirki_Toolkit::fonts()->get_font_choices()); $this->assertEquals(Kirki_Fonts::is_google_font('Open Sans'), Kirki_Toolkit::fonts()->is_google_font('Open Sans')); $this->assertEquals(Kirki_Fonts::get_google_font_uri(array('Roboto')), Kirki_Toolkit::fonts()->get_google_font_uri(array('Roboto'))); $this->assertEquals(Kirki_Fonts::get_google_font_subsets(), Kirki_Toolkit::fonts()->get_google_font_subsets()); $this->assertEquals(Kirki_Fonts::choose_google_font_variants('Roboto'), Kirki_Toolkit::fonts()->choose_google_font_variants('Roboto')); $this->assertEquals(Kirki_Fonts::get_standard_fonts(), Kirki_Toolkit::fonts()->get_standard_fonts()); $this->assertEquals(Kirki_Fonts::get_font_stack(''), Kirki_Toolkit::fonts()->get_font_stack('')); $this->assertEquals(Kirki_Fonts::sanitize_font_choice(''), Kirki_Toolkit::fonts()->sanitize_font_choice('')); $this->assertEquals(Kirki_Fonts::get_google_fonts(), Kirki_Toolkit::fonts()->get_google_fonts()); }
public function to_json() { parent::to_json(); $fields = $this->fields; $i18n = Kirki_Toolkit::i18n(); $default_image_button_labels = array('default' => $i18n['add-image'], 'remove' => $i18n['remove'], 'change' => $i18n['change-image'], 'placeholder' => $i18n['no-image-selected']); foreach ($fields as $key => $field) { if ($field['type'] != 'image') { continue; } $fields[$key]['buttonLabels'] = $default_image_button_labels; } $this->json['fields'] = $fields; }
/** * Returns the Kirki object */ function Kirki() { // Make sure the class is instanciated $kirki = Kirki_Toolkit::get_instance(); $kirki->font_registry = new Kirki_Google_Fonts_Registry(); $kirki->api = new Kirki(); $kirki->scripts = new Kirki_Scripts_Registry(); $kirki->styles = array('back' => new Kirki_Styles_Customizer(), 'front' => new Kirki_Styles_Frontend()); /** * The path of the current Kirki instance */ Kirki::$path = dirname(__FILE__); return $kirki; }
/** * Render the control's content. */ protected function render_content() { ?> <?php $i18n = Kirki_Toolkit::i18n(); ?> <label for="toggle_<?php echo $this->id; ?> "> <span class="customize-control-title"> <?php echo esc_attr($this->label); ?> <?php if (!empty($this->description)) { ?> <?php // The description has already been sanitized in the Fields class, no need to re-sanitize it. ?> <span class="description customize-control-description"><?php echo $this->description; ?> </span> <?php } ?> </span> </label> <input name="toggle_<?php echo $this->id; ?> " id="toggle_<?php echo $this->id; ?> " type="checkbox" value="<?php echo esc_attr($this->value()); ?> " <?php $this->link(); checked($this->value()); ?> /> <script>jQuery(document).ready(function($){$('[id="toggle_<?php echo $this->id; ?> "]').checkbox({toggle:true});});</script> <?php }
/** * Properly set the Kirki URL for assets * Determines if Kirki is installed as a plugin, in a child theme, or a parent theme * and then does some calculations to get the proper URL for its CSS & JS assets * * @return string */ public function set_url() { /** * Are we on a parent theme? */ if (Kirki_Toolkit::is_parent_theme(__FILE__)) { $relative_url = str_replace(Kirki_Toolkit::clean_file_path(get_template_directory()), '', dirname(dirname(__FILE__))); Kirki::$url = trailingslashit(get_template_directory_uri() . $relative_url); } elseif (Kirki_Toolkit::is_child_theme(__FILE__)) { $relative_url = str_replace(Kirki_Toolkit::clean_file_path(get_stylesheet_directory()), '', dirname(dirname(__FILE__))); Kirki::$url = trailingslashit(get_stylesheet_directory_uri() . $relative_url); } else { Kirki::$url = plugin_dir_url(dirname(__FILE__) . 'kirki.php'); } }
public function to_json() { parent::to_json(); if (isset($this->default)) { $this->json['default'] = $this->default; } else { $this->json['default'] = $this->setting->default; } $this->json['js_vars'] = $this->js_vars; $this->json['output'] = $this->output; $this->json['value'] = $this->value(); $this->json['choices'] = $this->choices; $this->json['link'] = $this->get_link(); $this->json['help'] = $this->help; $this->json['id'] = $this->id; $this->json['i18n'] = Kirki_Toolkit::i18n(); }
public function test() { $this->assertEquals(kirki_get_option(), Kirki::get_option()); $this->assertEquals(kirki_sanitize_hex('#ffffff'), Kirki_Color::sanitize_hex('#ffffff')); $this->assertEquals(kirki_get_rgb('#ffffff'), Kirki_Color::get_rgb('#ffffff')); $this->assertEquals(kirki_get_rgba('#ffffff'), Kirki_Color::get_rgba('#ffffff')); $this->assertEquals(kirki_get_brightness('#ffffff'), Kirki_Color::get_brightness('#ffffff')); $font_registry = Kirki_Toolkit::fonts(); $this->assertEquals(Kirki_Fonts::get_all_fonts(), $font_registry->get_all_fonts()); $this->assertEquals(Kirki_Fonts::get_font_choices(), $font_registry->get_font_choices()); $this->assertEquals(Kirki_Fonts::is_google_font('foo'), $font_registry->is_google_font('foo')); $this->assertEquals(Kirki_Fonts::get_google_font_uri(array('foo')), $font_registry->get_google_font_uri(array('foo'))); $this->assertEquals(Kirki_Fonts::get_google_font_subsets(), $font_registry->get_google_font_subsets()); $this->assertEquals(Kirki_Fonts::choose_google_font_variants('Roboto'), $font_registry->choose_google_font_variants('Roboto')); $this->assertEquals(Kirki_Fonts::get_standard_fonts(), $font_registry->get_standard_fonts()); $this->assertEquals(Kirki_Fonts::get_font_stack('foo'), $font_registry->get_font_stack('foo')); $this->assertEquals(Kirki_Fonts::sanitize_font_choice('foo'), $font_registry->sanitize_font_choice('foo')); $this->assertEquals(Kirki_Fonts::get_google_fonts(), $font_registry->get_google_fonts()); }
public function to_json() { parent::to_json(); $this->json['l10n'] = Kirki_Toolkit::i18n(); $this->json['choices'] = array(); if (is_array($this->choices)) { foreach ($this->choices as $choice => $value) { if (true === $value) { $this->json['choices'][$choice] = true; } } } if (is_array($this->json['default'])) { foreach ($this->json['default'] as $key => $value) { if (isset($this->json['choices'][$key]) && !isset($this->json['value'][$key])) { $this->json['value'][$key] = $value; } } } }
/** * Returns the Kirki object */ function Kirki() { // Make sure the class is instanciated $kirki = Kirki_Toolkit::get_instance(); $kirki->font_registry = new Kirki_Google_Fonts_Registry(); $kirki->api = new Kirki(); $kirki->scripts = new Kirki_Scripts_Registry(); $kirki->styles = array('back' => new Kirki_Styles_Customizer(), 'front' => new Kirki_Styles_Frontend()); /** * The path of the current Kirki instance */ Kirki::$path = dirname(__FILE__); /** * Get the URL of the current Kirki instance. * In order to do that, first we'll have to determine if we're using Kirki * as a plugin, or if it's embedded in a theme. * We'll also have to do some ugly stuff below because Windows is messy * and we want to accomodate users using XAMPP for their development. * Seriously though guys, you should consider using Vagrant instead. */ $dirname_no_slashes = str_replace(array('\\', '/'), '', dirname(__FILE__)); $plugindir_no_slashes = str_replace(array('\\', '/'), '', WP_PLUGIN_DIR); $themedir_no_slashes = str_replace(array('\\', '/'), '', get_template_directory()); if (false !== strpos($dirname_no_slashes, $plugindir_no_slashes)) { /** * Kirki is activated as a plugin. */ Kirki::$url = plugin_dir_url(__FILE__); } else { if (false !== strpos($dirname_no_slashes, $themedir_no_slashes)) { /** * Kirki is embedded in a theme */ Kirki::$url = get_template_directory_uri() . str_replace(get_template_directory(), '', dirname(__FILE__)); } } return $kirki; }
/** * Returns the Kirki object */ function Kirki() { // Make sure the class is instanciated $kirki = Kirki_Toolkit::get_instance(); $kirki->font_registry = new Kirki_Fonts_Font_Registry(); $kirki->api = new Kirki(); $kirki->scripts = new Kirki_Scripts_Registry(); $kirki->styles = array('back' => new Kirki_Styles_Customizer(), 'front' => new Kirki_Styles_Frontend()); /** * The path of the current Kirki instance */ Kirki::$path = dirname(__FILE__); /** * The URL of the current Kirki instance */ if (false !== strpos(dirname(__FILE__), WP_PLUGIN_DIR)) { /** * Kirki is activated as a plugin. */ Kirki::$url = plugin_dir_url(__FILE__); } else { if (false !== strpos(dirname(__FILE__), get_template_directory())) { /** * Kirki is embedded in a theme */ Kirki::$url = get_template_directory_uri() . str_replace(get_template_directory(), '', dirname(__FILE__)); } } /** * Apply the filters to the Kirki::$url */ $config = apply_filters('kirki/config', array()); if (isset($config['url_path'])) { Kirki::$url = esc_url_raw($config['url_path']); } return $kirki; }
function Kirki() { $kirki = Kirki_Toolkit::get_instance(); return $kirki; }
public static function get_google_fonts() { $font_registry = Kirki_Toolkit::fonts(); return $font_registry->get_google_fonts(); }
/** * Render the control's content. */ protected function render_content() { ?> <?php $i18n = Kirki_Toolkit::i18n(); ?> <label for="switch_<?php echo $this->id; ?> "> <span class="customize-control-title"> <?php echo esc_attr($this->label); ?> <?php if (!empty($this->description)) { ?> <?php // The description has already been sanitized in the Fields class, no need to re-sanitize it. ?> <span class="description customize-control-description"><?php echo $this->description; ?> </span> <?php } ?> </span> </label> <input name="switch_<?php echo $this->id; ?> " id="switch_<?php echo $this->id; ?> " type="checkbox" value="<?php echo esc_attr($this->value()); ?> " <?php $this->link(); ?> <?php if ('1' == $this->value()) { echo 'checked'; } ?> /> <script> jQuery(document).ready(function($){ $('[id="switch_<?php echo $this->id; ?> "]').checkbox({ toggle:true, labels:{ on:"<?php echo !empty($this->choices) && isset($this->choices['on']) ? $this->choices['on'] : $i18n['ON']; ?> ", off:"<?php echo !empty($this->choices) && isset($this->choices['off']) ? $this->choices['off'] : $i18n['OFF']; ?> " } }); }); </script> <?php if ('0' == $this->value()) { ?> <script>jQuery(document).ready(function($){$('#customize-control-<?php echo $this->id; ?> .fs-checkbox').removeClass('fs-checkbox-checked');});</script> <?php } ?> <?php }
public function google_link() { /** * Get the array of fields from the Kirki object. */ $fields = Kirki::$fields; /** * Early exit if no fields are found. */ if (empty($fields)) { return; } $fonts = array(); /** * Run a loop for our fields */ foreach ($fields as $field) { /** * No reason to proceed any further if no 'output' has been defined * or if it's not defined as an array. */ if (!isset($field['output']) || !is_array($field['output'])) { continue; } /** * Run through each of our "output" items in the array separately. */ foreach ($field['output'] as $output) { $valid = false; /** * If the field-type exists and is set to "typography" * then we need some extra checks to figure out if we need to proceed. */ if (isset($field['type']) && 'typography' == $field['type']) { if (isset($field['choices']) && isset($field['choices']['font-family']) && $field['choices']['font-family']) { $valid = true; } } /** * Check if the "property" of this item is related to typography. */ if (isset($output['property']) && in_array($output['property'], array('font-family', 'font-weight', 'font-subset'))) { $valid = true; } /** * If the $valid var is not true, then we don't need to proceed. * Continue to the next item in the array. */ if (!$valid) { continue; } /** * Get the value of this field */ $value = Kirki_Values::get_sanitized_field_value($field); /** * Typography fields arew a bit more complex than usual fields. * We need to get the sub-items of the array * and then base our calculations on these. */ if ('typography' == $field['type']) { /** * Add the font-family to the array */ if (isset($value['font-family'])) { $fonts[]['font-family'] = $value['font-family']; } /** * Add the font-weight to the array */ if (isset($value['font-weight'])) { $fonts[]['font-weight'] = $value['font-weight']; } } else { if ('font-family' == $output['property']) { /** * Add the font-family to the array */ $fonts[]['font-family'] = $value; } else { if ('font-weight' == $output['property']) { /** * Add font-weight to the array */ $fonts[]['font-weight'] = $value; } else { if ('font-subset' == $output['property']) { /** * add font subsets to the array */ $fonts[]['subsets'] = $value; } } } } } } /** * Start going through all the items in the $fonts array. */ foreach ($fonts as $font) { /** * Do we have font-families? */ if (isset($font['font-family'])) { $font_families = !isset($font_families) ? array() : $font_families; $font_families[] = $font['font-family']; /** * Determine if we need to create a google-fonts link or not. */ if (!isset($has_google_font)) { if (Kirki_Toolkit::fonts()->is_google_font($font['font-family'])) { $has_google_font = true; } } } /** * Do we have font-weights? */ if (isset($font['font-weight'])) { $font_weights = !isset($font_weights) ? array() : $font_weights; $font_weights[] = $font['font-weight']; } /** * Do we have font-subsets? */ if (isset($font['subsets'])) { $font_subsets = !isset($font_subsets) ? array() : $font_subsets; $font_subsets[] = $font['subsets']; } } /** * Make sure there are no empty values and define some sane defaults. */ $font_families = !isset($font_families) || empty($font_families) ? false : $font_families; $font_weights = !isset($font_weights) || empty($font_weights) ? array('400') : $font_weights; $font_subsets = !isset($font_subsets) || empty($font_subsets) ? array('all') : $font_subsets; /** * Get rid of duplicate values */ if (is_array($font_families) && !empty($font_families)) { $font_families = array_unique($font_families); } if (is_array($font_weights) && !empty($font_weights)) { $font_weights = array_unique($font_weights); } if (is_array($font_subsets) && !empty($font_subsets)) { $font_subsets = array_unique($font_subsets); } if (!isset($has_google_font) || !$has_google_font) { $font_families = false; } // Return the font URL. return $font_families ? Kirki_Toolkit::fonts()->get_google_font_uri($font_families, $font_weights, $font_subsets) : false; }
/** * Return an array of standard websafe fonts. * * @return array Standard websafe fonts. */ public function get_standard_fonts() { $i18n = Kirki_Toolkit::i18n(); if (null == $this->standard_fonts) { $this->standard_fonts = apply_filters('kirki/fonts/standard_fonts', array('serif' => array('label' => $i18n['serif'], 'stack' => 'Georgia,Times,"Times New Roman",serif'), 'sans-serif' => array('label' => $i18n['sans-serif'], 'stack' => 'Helvetica,Arial,sans-serif'), 'monospace' => array('label' => $i18n['monospace'], 'stack' => 'Monaco,"Lucida Sans Typewriter","Lucida Typewriter","Courier New",Courier,monospace'))); } return $this->standard_fonts; }
/** * The background choices. * @return array<string,array> */ public static function background_choices() { $i18n = Kirki_Toolkit::i18n(); return array('repeat' => array('no-repeat' => $i18n['no-repeat'], 'repeat' => $i18n['repeat-all'], 'repeat-x' => $i18n['repeat-x'], 'repeat-y' => $i18n['repeat-y'], 'inherit' => $i18n['inherit']), 'size' => array('inherit' => $i18n['inherit'], 'cover' => $i18n['cover'], 'contain' => $i18n['contain']), 'attach' => array('inherit' => $i18n['inherit'], 'fixed' => $i18n['fixed'], 'scroll' => $i18n['scroll']), 'position' => array('left-top' => $i18n['left-top'], 'left-center' => $i18n['left-center'], 'left-bottom' => $i18n['left-bottom'], 'right-top' => $i18n['right-top'], 'right-center' => $i18n['right-center'], 'right-bottom' => $i18n['right-bottom'], 'center-top' => $i18n['center-top'], 'center-center' => $i18n['center-center'], 'center-bottom' => $i18n['center-bottom'])); }
function test_i18n() { $this->assertTrue(is_array(Kirki_Toolkit::i18n())); }
public function google_link() { // Get the array of fields $fields = Kirki::$fields; // Early exit if no fields are found. if (empty($fields)) { return; } $fonts = array(); foreach ($fields as $field) { /** * Sanitize the field */ $field = Kirki_Field::sanitize_field($field); if (!is_array($field['output'])) { continue; } foreach ($field['output'] as $output) { if (in_array($output['property'], array('font-family', 'font-weight', 'font-subset'))) { /** * Get the value of the field */ $config_id = Kirki::get_config_id($field); $settings = $field['settings']; if ('option' == Kirki::$config[$config_id]['option_type'] && '' != Kirki::$config[$config_id]['option_name']) { $settings = str_replace(array(']', Kirki::$config[$config_id]['option_name'] . '['), '', $field['settings']); } $value = Kirki::get_option($config_id, $settings); if ('font-family' == $output['property']) { /** * Add the font-family to the array */ $fonts[]['font-family'] = $value; } else { if ('font-weight' == $output['property']) { /** * Add font-weight to the array */ $fonts[]['font-weight'] = $value; } else { if ('font-subset' == $output['property']) { /** * add font subsets to the array */ $fonts[]['subsets'] = $value; } } } } } } foreach ($fonts as $font) { // Do we have font-families? if (isset($font['font-family'])) { $font_families = !isset($font_families) ? array() : $font_families; $font_families[] = $font['font-family']; if (Kirki_Toolkit::fonts()->is_google_font($font['font-family'])) { $has_google_font = true; } } // Do we have font-weights? if (isset($font['font-weight'])) { $font_weights = !isset($font_weights) ? array() : $font_weights; $font_weights[] = $font['font-weight']; } // Do we have font-subsets? if (isset($font['subsets'])) { $font_subsets = !isset($font_subsets) ? array() : $font_subsets; $font_subsets[] = $font['subsets']; } } // Make sure there are no empty values and define defaults. $font_families = !isset($font_families) || empty($font_families) ? false : $font_families; $font_weights = !isset($font_weights) || empty($font_weights) ? '400' : $font_weights; $font_subsets = !isset($font_subsets) || empty($font_subsets) ? 'all' : $font_subsets; if (!isset($has_google_font) || !$has_google_font) { $font_families = false; } // Return the font URL. return $font_families ? Kirki_Toolkit::fonts()->get_google_font_uri($font_families, $font_weights, $font_subsets) : false; }
public function google_link() { // Get the array of fields $fields = Kirki::$fields; // Early exit if no fields are found. if (empty($fields)) { return; } $fonts = array(); foreach ($fields as $field) { // Sanitize the field's output & settings_raw items. $field['output'] = Kirki_Field::sanitize_output($field); $field['settings_raw'] = Kirki_Field::sanitize_settings_raw($field); // Make sure output is properly formatted if (isset($field['output']) && is_array($field['output'])) { foreach ($field['output'] as $output) { if (in_array($output['property'], array('font-family', 'font-weight', 'font-subset'))) { // The value of this control $value = Kirki::get_option($field['settings_raw']); if ('font-family' == $output['property']) { // Add the font-family to the array $fonts[]['font-family'] = $value; } else { if ('font-weight' == $output['property']) { // Add font-weight to the array $fonts[]['font-weight'] = $value; } else { if ('font-subset' == $output['property']) { // add font subsets to the array $fonts[]['subsets'] = $value; } } } } } } } foreach ($fonts as $font) { // Do we have font-families? if (isset($font['font-family'])) { $font_families = !isset($font_families) ? array() : $font_families; $font_families[] = $font['font-family']; if (Kirki_Toolkit::fonts()->is_google_font($font['font-family'])) { $has_google_font = true; } } // Do we have font-weights? if (isset($font['font-weight'])) { $font_weights = !isset($font_weights) ? array() : $font_weights; $font_weights[] = $font['font-weight']; } // Do we have font-subsets? if (isset($font['subsets'])) { $font_subsets = !isset($font_subsets) ? array() : $font_subsets; $font_subsets[] = $font['subsets']; } } // Make sure there are no empty values and define defaults. $font_families = !isset($font_families) || empty($font_families) ? false : $font_families; $font_weights = !isset($font_weights) || empty($font_weights) ? '400' : $font_weights; $font_subsets = !isset($font_subsets) || empty($font_subsets) ? 'all' : $font_subsets; if (!isset($has_google_font) || !$has_google_font) { $font_families = false; } // Return the font URL. return $font_families ? Kirki_Toolkit::fonts()->get_google_font_uri($font_families, $font_weights, $font_subsets) : false; }