public function add_settings($args)
 {
     if (isset($args['settings']) && is_array($args['settings'])) {
         $settings = $args['settings'];
         $defaults = isset($args['default']) ? $args['default'] : array();
         $sanitize_callback = $args['sanitize_callback'];
         foreach ($settings as $setting_key => $setting_value) {
             $default = isset($defaults[$setting_key]) ? $defaults[$setting_key] : '';
             $transport = isset($args['transport']) ? $args['transport'] : 'refresh';
             if (isset($args['sanitize_callback']) && is_array($args['sanitize_callback'])) {
                 if (isset($args['sanitize_callback'][$setting_key])) {
                     $sanitize_callback = Kirki_Field::sanitize_callback('', array('sanitize_callback' => $args['sanitize_callback'][$setting_key]));
                 }
             }
             $this->wp_customize->add_setting($setting_value, array('default' => $default, 'type' => $args['option_type'], 'capability' => $args['capability'], 'sanitize_callback' => $sanitize_callback, 'transport' => $transport));
         }
     }
     if (isset($args['type']) && array_key_exists($args['type'], Kirki_Control::$setting_types)) {
         // We must instantiate a custom class for the setting
         $setting_classname = Kirki_Control::$setting_types[$args['type']];
         $this->wp_customize->add_setting(new $setting_classname($this->wp_customize, $args['settings'], array('default' => isset($args['default']) ? $args['default'] : '', 'type' => $args['option_type'], 'capability' => $args['capability'], 'transport' => isset($args['transport']) ? $args['transport'] : 'refresh', 'sanitize_callback' => $args['sanitize_callback'])));
     } else {
         $this->wp_customize->add_setting($args['settings'], array('default' => isset($args['default']) ? $args['default'] : '', 'type' => $args['option_type'], 'capability' => $args['capability'], 'transport' => isset($args['transport']) ? $args['transport'] : 'refresh', 'sanitize_callback' => $args['sanitize_callback']));
     }
 }
示例#2
0
 /**
  * The class constructor.
  *
  * @var 	string		the setting ID.
  * @var 	string		theme_mod / option
  * @var 	array 		an array of arrays of the output arguments.
  * @var 	mixed		a callable function.
  */
 public static function css($field)
 {
     /**
      * Make sure the field is sanitized before proceeding any further.
      */
     $field = Kirki_Field::sanitize_field($field);
     /**
      * Get the config ID used in the Kirki class.
      */
     $config_id = Kirki::get_config_id($field);
     /**
      * Set class vars
      */
     self::$settings = $field['settings'];
     self::$output = $field['output'];
     self::$callback = $field['sanitize_callback'];
     /**
      * Get the value of this field
      */
     if ('option' == Kirki::$config[$config_id]['option_type'] && '' != Kirki::$config[$config_id]['option_name']) {
         self::$value = Kirki::get_option($config_id, str_replace(array(']', Kirki::$config[$config_id]['option_name'] . '['), '', $field['settings']));
     } else {
         self::$value = Kirki::get_option($config_id, $field['settings']);
     }
     /**
      * Returns the styles
      */
     if (!is_array(self::$value)) {
         return self::styles();
     }
 }
 /**
  * Constructor.
  * Since editor fields only work properly if there's a single tinyMCE instance
  * We'll be adding a global editor using the add_editor method.
  *
  * @access public
  * @param string $config_id    The ID of the config we want to use.
  *                             Defaults to "global".
  *                             Configs are handled by the Kirki_Config class.
  * @param array  $args         The arguments of the field.
  */
 public function __construct($config_id = 'global', $args = array())
 {
     // Call the parent-class constructor.
     parent::__construct($config_id, $args);
     // Add the editor.
     add_action('customize_controls_print_footer_scripts', array(__CLASS__, 'add_editor'));
 }
 public function generate_script()
 {
     global $wp_customize;
     // Early exit if we're not in the customizer
     if (!isset($wp_customize)) {
         return;
     }
     // Get an array of all the fields
     $fields = Kirki::$fields;
     $script = '';
     // Parse the fields and create the script.
     foreach ($fields as $field) {
         $field['transport'] = Kirki_Field::sanitize_transport($field);
         $field['js_vars'] = Kirki_Field::sanitize_js_vars($field);
         if (!is_null($field['js_vars']) && 'postMessage' == $field['transport']) {
             foreach ($field['js_vars'] as $js_vars) {
                 $units = !empty($js_vars['units']) ? " + '" . $js_vars['units'] . "'" : '';
                 $prefix = !empty($js_vars['prefix']) ? "'" . $js_vars['prefix'] . "' + " : '';
                 $script .= 'wp.customize( \'' . Kirki_Field::sanitize_settings($field) . '\', function( value ) {';
                 $script .= 'value.bind( function( newval ) {';
                 if ('html' == $js_vars['function']) {
                     $script .= '$(\'' . $js_vars['element'] . '\').html( newval );';
                 } else {
                     $script .= '$(\'' . $js_vars['element'] . '\').' . $js_vars['function'] . '(\'' . $js_vars['property'] . '\', ' . $prefix . 'newval' . $units . ' );';
                 }
                 $script .= '}); });';
             }
         }
     }
     return $script;
 }
示例#5
0
 /**
  * The class constructor.
  *
  * @var 	string		the setting ID.
  * @var 	string		theme_mod / option
  * @var 	array 		an array of arrays of the output arguments.
  * @var 	mixed		a callable function.
  */
 public static function css($setting = '', $type = 'theme_mod', $output = array(), $callback = '', $return_array = false)
 {
     // No need to proceed any further if we don't have the required arguments.
     if ('' == $setting || empty($output)) {
         return;
     }
     self::$settings = $setting;
     self::$type = $type;
     self::$output = Kirki_Field::sanitize_output(array('output' => $output));
     self::$value = self::get_value();
     self::$callback = $callback;
     return true === $return_array ? self::styles() : self::styles_parse(self::add_prefixes(self::styles()));
 }
 /**
  * Build the background fields.
  * Takes a single field with type = background and explodes it to multiple controls.
  *
  * @param array
  * @return null|array<Array>
  */
 public static function explode($field)
 {
     $i18n = Kirki_Toolkit::i18n();
     $choices = self::background_choices();
     // Early exit if this is not a background field.
     if ('background' != $field['type']) {
         return;
     }
     // Sanitize field
     $field = Kirki_Field::sanitize_field($field);
     // No need to proceed any further if no defaults have been set.
     // We build the array of fields based on what default values have been defined.
     if (!isset($field['default']) || !is_array($field['default'])) {
         return;
     }
     $fields = array();
     $i = 0;
     foreach ($field['default'] as $key => $value) {
         // No need to process the opacity, it is factored in the color control.
         if ('opacity' == $key) {
             continue;
         }
         $key = esc_attr($key);
         $setting = $key;
         $help = $field['help'];
         $description = isset($i18n['background-' . $key]) ? $i18n['background-' . $key] : '';
         $output_property = 'background-' . $key;
         $label = 0 === $i ? $field['label'] : '';
         $type = 'select';
         switch ($key) {
             case 'color':
                 $type = false !== strpos($field['default']['color'], 'rgba') ? 'color-alpha' : 'color';
                 $type = isset($field['default']['opacity']) ? 'color-alpha' : $type;
                 break;
             case 'image':
                 $type = 'image';
                 break;
             case 'attach':
                 $output_property = 'background-attachment';
                 $description = $i18n['background-attachment'];
                 break;
             default:
                 $help = '';
                 break;
         }
         $fields[$field['settings'] . '_' . $setting] = array_merge($field, array('type' => $type, 'label' => $label, 'settings' => $field['settings'] . '_' . $setting, 'help' => $help, 'section' => $field['section'], 'priority' => $field['priority'], 'required' => $field['required'], 'description' => $description, 'default' => $value, 'id' => Kirki_Field::sanitize_id(array('settings' => Kirki_Field::sanitize_settings(array('settings' => $field['settings'] . '_' . $setting)))), 'choices' => isset($choices[$key]) ? $choices[$key] : array(), 'output' => '' != $field['output'] ? array(array('element' => $field['output'], 'property' => $output_property)) : '', 'sanitize_callback' => Kirki_Field::fallback_callback($type)));
         $i++;
     }
     return $fields;
 }
 /**
  * loop through all fields and create an array of style definitions
  */
 public function loop_controls()
 {
     $fields = Kirki::$fields;
     $css = array();
     // Early exit if no fields are found.
     if (empty($fields)) {
         return;
     }
     foreach ($fields as $field) {
         // Only continue if $field['output'] is set
         if (isset($field['output']) && 'background' != $field['type']) {
             $css = array_merge_recursive($css, Kirki_Output::css(Kirki_Field::sanitize_settings_raw($field), Kirki_Field::sanitize_type($field), Kirki_Field::sanitize_output($field), isset($field['output']['callback']) ? $field['output']['callback'] : '', true));
         }
     }
     return Kirki_Output::styles_parse(Kirki_Output::add_prefixes($css));
 }
 public function generate_script()
 {
     global $wp_customize;
     // Early exit if we're not in the customizer
     if (!isset($wp_customize)) {
         return;
     }
     // Get an array of all the fields
     $fields = Kirki::$fields;
     $script = 'jQuery( "#kirki-styles-inline-css" ).remove();';
     $styles = array();
     // Parse the fields and create the script.
     foreach ($fields as $field) {
         $field['transport'] = Kirki_Field::sanitize_transport($field);
         $field['js_vars'] = Kirki_Field::sanitize_js_vars($field);
         if (!empty($field['setting'])) {
             $inline_id = 'kirki-' . $field['setting'];
             $styles[] = '<style id="' . esc_attr($inline_id) . '">' . Kirki_Output::generate_css_by_fields(array($field)) . '</style>';
         }
         if ('postMessage' == $field['transport']) {
             $script .= 'wp.customize( \'' . Kirki_Field::sanitize_settings($field) . '\', function( value ) {';
             $script .= 'value.bind( function( newval ) {';
             if (!is_null($field['js_vars'])) {
                 foreach ($field['js_vars'] as $js_vars) {
                     if ('html' == $js_vars['function']) {
                         $script .= '$(\'' . esc_js($js_vars['element']) . '\').html( newval );';
                     } elseif ('css' == $js_vars['function']) {
                         $script .= '$(\'' . esc_js($js_vars['element']) . '\').css(\'' . esc_js($js_vars['property']) . '\', newval' . (!empty($js_vars['units']) ? ' + \'' . $js_vars['units'] . "'" : '') . ' );';
                     }
                 }
             } else {
                 $output_unit = '';
                 if (!empty($field['output']) && !empty($field['output']['units'])) {
                     $output_unit = $field['output']['units'];
                 }
                 $inline_id = 'kirki-' . $field['setting'];
                 $placeholder_inline_css = Kirki_Output::generate_css_by_fields(array($field), true);
                 $script .= 'jQuery( "#' . $inline_id . '" )[0].innerHTML = "' . str_replace(array('{value}', '&gt;'), array('" + newval + "' . $output_unit, '>'), esc_js($placeholder_inline_css)) . '";';
             }
             $script .= '}); });';
         }
     }
     return array($script, $styles);
 }
 /**
  * Add the help bubble
  */
 public function generate_script()
 {
     $fields = Kirki::$fields;
     $scripts = array();
     foreach ($fields as $field) {
         $field['help'] = Kirki_Field::sanitize_help($field);
         $field['settings'] = Kirki_Field::sanitize_settings($field);
         if (!empty($field['help'])) {
             $content = "<a href='#' class='tooltip hint--left' data-hint='" . strip_tags(esc_html($field['help'])) . "'><span class='dashicons dashicons-info'></span></a>";
             $scripts[] = '$( "' . $content . '" ).prependTo( "#customize-control-' . $field['settings'] . '" );';
         }
     }
     // No need to echo anything if the script is empty
     if (empty($scripts)) {
         return;
     }
     // Make sure we don't add any duplicates
     $scripts = array_unique($scripts);
     // Convert array to string
     $script = implode('', $scripts);
     return $script;
 }
 /**
  * Build the background fields.
  * Takes a single field with type = background and explodes it to multiple controls.
  *
  * @param array
  * @return null|array
  */
 public static function explode($field)
 {
     $i18n = Kirki_Toolkit::i18n();
     $choices = self::background_choices();
     // Early exit if this is not a background field.
     if ('background' != $field['type']) {
         return;
     }
     // Sanitize field
     $field = Kirki_Field::sanitize_field($field);
     // No need to proceed any further if no defaults have been set.
     // We build the array of fields based on what default values have been defined.
     if (!isset($field['default']) || !is_array($field['default'])) {
         return;
     }
     $fields = array();
     $i = 0;
     foreach ($field['default'] as $key => $value) {
         // No need to process the opacity, it is factored in the color control.
         if ('opacity' == $key) {
             continue;
         }
         $key = esc_attr($key);
         $setting = $key;
         $help = $field['help'];
         $description = isset($i18n['background-' . $key]) ? $i18n['background-' . $key] : '';
         $output_property = 'background-' . $key;
         $label = 0 === $i ? $field['label'] : '';
         $type = 'select';
         switch ($key) {
             case 'color':
                 /**
                  * Use 'color-alpha' instead of 'color' if default is an rgba value
                  * or if 'opacity' is set.
                  */
                 $type = false !== strpos($field['default']['color'], 'rgba') ? 'color-alpha' : 'color';
                 $type = isset($field['default']['opacity']) ? 'color-alpha' : $type;
                 if (isset($field['default']['opacity']) && false === strpos($value, 'rgb')) {
                     $value = Kirki_Color::get_rgba($value, $field['default']['opacity']);
                 }
                 break;
             case 'image':
                 $type = 'image';
                 break;
             case 'attach':
                 /**
                  * Small hack so that background attachments properly work.
                  */
                 $output_property = 'background-attachment';
                 $description = $i18n['background-attachment'];
                 break;
             default:
                 $help = '';
                 break;
         }
         /**
          * If we're using options & option_name is set, then we need to modify the setting.
          */
         if (isset($field['option_type']) && 'option' == $field['option_type'] && isset($field['option_name']) && !empty($field['option_name'])) {
             $property_setting = str_replace(']', '', str_replace($field['option_name'] . '[', '', $field['settings']));
             $property_setting = esc_attr($field['option_name']) . '[' . esc_attr($property_setting) . '_' . $setting . ']';
         } else {
             $property_setting = esc_attr($field['settings']) . '_' . $setting;
         }
         /**
          * Build the field.
          * We're merging with the original field here, so any extra properties are inherited.
          */
         $fields[$property_setting] = array_merge($field, array('type' => $type, 'label' => $label, 'settings' => $property_setting, 'help' => $help, 'section' => $field['section'], 'priority' => $field['priority'], 'required' => $field['required'], 'description' => $description, 'default' => $value, 'id' => Kirki_Field::sanitize_id(array('settings' => Kirki_Field::sanitize_settings(array('settings' => $field['settings'] . '_' . $setting)))), 'choices' => isset($choices[$key]) ? $choices[$key] : array(), 'output' => '' != $field['output'] ? array(array('element' => $field['output'], 'property' => $output_property)) : '', 'sanitize_callback' => Kirki_Field::fallback_callback($type)));
         $i++;
     }
     return $fields;
 }
示例#11
0
 /**
  * Build the variables.
  *
  * @return array 	('variable-name' => value)
  */
 public function get_variables()
 {
     $variables = array();
     foreach (self::$fields as $field) {
         if (isset($field['variables']) && false != $field['variables']) {
             foreach ($field['variables'] as $field_variable) {
                 if (isset($field_variable['name'])) {
                     $variable_name = esc_attr($field_variable['name']);
                     $variable_callback = isset($field_variable['callback']) && is_callable($field_variable['callback']) ? $field_variable['callback'] : false;
                     if ($variable_callback) {
                         $variables[$variable_name] = call_user_func($field_variable['callback'], self::get_option(Kirki_Field::sanitize_settings($field)));
                     } else {
                         $variables[$variable_name] = self::get_option($field['settings']);
                     }
                 }
             }
         }
     }
     return apply_filters('kirki/variable', $variables);
 }
示例#12
0
 /**
  * Find the config ID based on the field options
  */
 public static function get_config_id($field)
 {
     return Kirki_Field::get_config_id($field);
 }
示例#13
0
 /**
  * Build the variables.
  *
  * @return array 	('variable-name' => value)
  */
 public function get_variables()
 {
     $variables = array();
     /**
      * Loop through all fields
      */
     foreach (self::$fields as $field) {
         /**
          * Check if we have variables for this field
          */
         if (isset($field['variables']) && false != $field['variables'] && !empty($field['variables'])) {
             /**
              * Loop through the array of variables
              */
             foreach ($field['variables'] as $field_variable) {
                 /**
                  * Is the variable ['name'] defined?
                  * If yes, then we can proceed.
                  */
                 if (isset($field_variable['name'])) {
                     /**
                      * Sanitize the variable name
                      */
                     $variable_name = esc_attr($field_variable['name']);
                     /**
                      * Do we have a callback function defined?
                      * If not then set $variable_callback to false.
                      */
                     $variable_callback = isset($field_variable['callback']) && is_callable($field_variable['callback']) ? $field_variable['callback'] : false;
                     /**
                      * If we have a variable_callback defined then get the value of the option
                      * and run it through the callback function.
                      * If no callback is defined (false) then just get the value.
                      */
                     if ($variable_callback) {
                         $variables[$variable_name] = call_user_func($field_variable['callback'], self::get_option(Kirki_Field::sanitize_settings($field)));
                     } else {
                         $variables[$variable_name] = self::get_option($field['settings']);
                     }
                 }
             }
         }
     }
     /**
      * Pass the variables through a filter ('kirki/variable')
      * and return the array of variables
      */
     return apply_filters('kirki/variable', $variables);
 }
示例#14
0
 public static function generate_css_by_fields($fields, $placeholder = false)
 {
     // Early exit if no fields are found.
     if (empty($fields)) {
         return;
     }
     $css = array();
     foreach ($fields as $field) {
         // Only continue if $field['output'] is set
         if (isset($field['output']) && !empty($field['output']) && 'background' != $field['type']) {
             $css = array_merge_recursive($css, self::css(Kirki_Field::sanitize_field($field)));
         }
     }
     // Replace all values with placeholder
     if ($placeholder) {
         foreach ($css as $media_query => $styles) {
             foreach ($styles as $style => $style_array) {
                 foreach ($style_array as $property => $value) {
                     $css[$media_query][$style][$property] = '{value}';
                 }
             }
         }
     }
     if (is_array($css)) {
         return Kirki_Output::styles_parse(Kirki_Output::add_prefixes($css));
     }
     return;
 }
示例#15
0
 /**
  * Create a new field
  *
  * @var		string		the configuration ID for this field
  * @var		array		the field arguments
  */
 public static function add_field($config_id, $args)
 {
     Kirki_Field::add_field($config_id, $args);
 }
 /**
  * Test fallback_callback functionality
  */
 public function test_fallback_callback()
 {
     $this->assertEquals(array('Kirki_Sanitize_Values', 'color'), Kirki_Field::fallback_callback('global', array('type' => 'color')));
 }
示例#17
0
文件: deprecated.php 项目: wpmu/maera
 /**
  * Get the value of a field.
  * This is a deprecated function that we in use when there was no API.
  * Please use the Kirki::get_option() method instead.
  * Documentation is available for the new method on https://github.com/aristath/kirki/wiki/Getting-the-values
  */
 function kirki_get_option($option = '')
 {
     // Make sure the class is instanciated
     Kirki_Toolkit::get_instance();
     $values = array();
     // Get the array of all the fields.
     $fields = Kirki::$fields;
     // Get the config.
     $config = apply_filters('kirki/config', array());
     $config['options_type'] = isset($config['options_type']) ? esc_attr($config['options_type']) : 'theme_mod';
     $config['option_name'] = isset($config['option_name']) ? esc_attr($config['option_name']) : '';
     // If we're using options instead of theme_mods,
     // then first we'll have to get the array of all options.
     if ('option' == $config['options_type']) {
         if ('' == $config['option_name']) {
             // No option name is defined.
             // Each options is saved separately in the db, so we'll manually build the array here.
             foreach ($fields as $field) {
                 $values[Kirki_Field::sanitize_settings($field)] = get_option(Kirki_Field::sanitize_settings($field), Kirki_Field::sanitize_default($field));
             }
         } else {
             // An option_name has been defined so our options are all saved in an array there.
             $values = get_option($config['option_name']);
             foreach ($fields as $field) {
                 if (!isset($values[Kirki_Field::sanitize_settings_raw($field)])) {
                     $values[Kirki_Field::sanitize_settings_raw($field)] = maybe_unserialize(Kirki_Field::sanitize_default($field));
                 }
             }
         }
     }
     if ('' == $option) {
         // No option has been defined so we'll get all options and return an array
         // If we're using options then we already have the $values set above.
         // All we need here is a fallback for theme_mods
         if ('option' != $config['options_type']) {
             // We're using theme_mods
             $values = get_theme_mods();
         }
         // Early exit and return the array of all values
         return $values;
     }
     // If a value has been defined then we proceed.
     // Early exit if this option does not exist
     $field_id = 'option' == $config['options_type'] && '' != $config['option_name'] ? $config['option_name'] . '[' . $option . ']' : $option;
     if (!isset($fields[$field_id])) {
         return;
     }
     if ('option' == $config['options_type']) {
         // We're using options instead of theme_mods.
         // We already have the array of values set from above so we'll use that.
         $value = isset($values[$option]) ? $values[$option] : $fields[$option]['default'];
     } else {
         // We're using theme_mods
         $value = get_theme_mod($option, $fields[$option]['default']);
     }
     // Combine background options to a single array
     if ('background' == $fields[$field_id]['type']) {
         if ('option' == $config['options_type']) {
             $value = array('background-color' => isset($values[$option . '_color']) ? $values[$option . '_color'] : null, 'background-repeat' => isset($values[$option . '_repeat']) ? $values[$option . '_repeat'] : null, 'background-attachment' => isset($values[$option . '_attach']) ? $values[$option . '_attach'] : null, 'background-image' => isset($values[$option . '_image']) ? $values[$option . '_image'] : null, 'background-position' => isset($values[$option . '_position']) ? $values[$option . '_position'] : null, 'background-clip' => isset($values[$option . '_clip']) ? $values[$option . '_clip'] : null, 'background-size' => isset($values[$option . '_size']) ? $values[$option . '_size'] : null);
         } else {
             $value = array('background-color' => isset($fields[$field_id]['default']['color']) ? get_theme_mod($option . '_color', $fields[$field_id]['default']['color']) : null, 'background-repeat' => isset($fields[$field_id]['default']['repeat']) ? get_theme_mod($option . '_repeat', $fields[$field_id]['default']['repeat']) : null, 'background-attachment' => isset($fields[$field_id]['default']['attach']) ? get_theme_mod($option . '_attach', $fields[$field_id]['default']['attach']) : null, 'background-image' => isset($fields[$field_id]['default']['image']) ? get_theme_mod($option . '_image', $fields[$field_id]['default']['image']) : null, 'background-position' => isset($fields[$field_id]['default']['position']) ? get_theme_mod($option . '_position', $fields[$field_id]['default']['position']) : null, 'background-clip' => isset($fields[$field_id]['default']['clip']) ? get_theme_mod($option . '_clip', $fields[$field_id]['default']['clip']) : null, 'background-size' => isset($fields[$field_id]['default']['size']) ? get_theme_mod($option . '_size', $fields[$field_id]['default']['size']) : null);
         }
     }
     // Return the single value.
     // Pass it through maybe_unserialize so we're sure we get a proper value.
     return maybe_unserialize($value);
 }
 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;
 }
示例#19
0
 public function test_fallback_callback()
 {
     $this->assertEquals(array('Kirki_Sanitize', 'checkbox'), Kirki_Field::fallback_callback('checkbox'));
     $this->assertEquals(array('Kirki_Sanitize', 'color'), Kirki_Field::fallback_callback('color-alpha'));
     $this->assertEquals(array('Kirki_Sanitize', 'color'), Kirki_Field::fallback_callback('color'));
     $this->assertEquals(array('Kirki_Sanitize', 'unfiltered'), Kirki_Field::fallback_callback('custom'));
     $this->assertEquals(array('Kirki_Sanitize', 'dropdown_pages'), Kirki_Field::fallback_callback('dropdown-pages'));
     $this->assertEquals('esc_textarea', Kirki_Field::fallback_callback('editor'));
     $this->assertEquals('esc_url_raw', Kirki_Field::fallback_callback('image'));
     $this->assertEquals(array('Kirki_Sanitize', 'multicheck'), Kirki_Field::fallback_callback('multicheck'));
     $this->assertEquals(array('Kirki_Sanitize', 'number'), Kirki_Field::fallback_callback('number'));
     $this->assertEquals('esc_attr', Kirki_Field::fallback_callback('palette'));
     $this->assertEquals('esc_attr', Kirki_Field::fallback_callback('radio-buttonset'));
     $this->assertEquals('esc_attr', Kirki_Field::fallback_callback('radio-image'));
     $this->assertEquals('esc_attr', Kirki_Field::fallback_callback('radio'));
     $this->assertEquals('esc_attr', Kirki_Field::fallback_callback('select'));
     $this->assertEquals(array('Kirki_Sanitize', 'number'), Kirki_Field::fallback_callback('slider'));
     $this->assertEquals(array('Kirki_Sanitize', 'sortable'), Kirki_Field::fallback_callback('sortable'));
     $this->assertEquals(array('Kirki_Sanitize', 'checkbox'), Kirki_Field::fallback_callback('switch'));
     $this->assertEquals('esc_textarea', Kirki_Field::fallback_callback('text'));
     $this->assertEquals('esc_textarea', Kirki_Field::fallback_callback('textarea'));
     $this->assertEquals(array('Kirki_Sanitize', 'checkbox'), Kirki_Field::fallback_callback('toggle'));
     $this->assertEquals('esc_url_raw', Kirki_Field::fallback_callback('upload'));
 }
 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;
 }