Exemplo n.º 1
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();
     }
 }
 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;
 }