/**
  * loop through all fields and create an array of style definitions
  */
 public static function loop_controls()
 {
     // Get an instance of the Kirki_Styles_Output_CSS class.
     // This will make sure google fonts and backup fonts are loaded.
     Kirki_Styles_Output_CSS::get_instance();
     $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']) && !empty($field['output']) && 'background' != $field['type']) {
             if (function_exists('array_replace_recursive')) {
                 $css = array_replace_recursive($css, Kirki_Styles_Output_CSS::css($field));
             } else {
                 $css = Kirki_Helper::array_replace_recursive($css, Kirki_Styles_Output_CSS::css($field));
             }
         }
     }
     if (is_array($css)) {
         return Kirki_Styles_Output_CSS::styles_parse(Kirki_Styles_Output_CSS::add_prefixes($css));
     }
     return;
 }
 /**
  * Refresh the parameters passed to the JavaScript via JSON.
  *
  * @access public
  */
 public function to_json()
 {
     parent::to_json();
     // If no palette has been defined, use Material Design Palette.
     if (!isset($this->json['choices']['colors']) || empty($this->json['choices']['colors'])) {
         $this->json['choices']['colors'] = Kirki_Helper::get_material_design_colors('primary');
     }
     if (!isset($this->json['choices']['size']) || empty($this->json['choices']['size'])) {
         $this->json['choices']['size'] = 42;
     }
 }
 /**
  * loop through all fields and create an array of style definitions
  */
 public static 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']) && !empty($field['output']) && 'background' != $field['type']) {
             if (function_exists('array_replace_recursive')) {
                 $css = array_replace_recursive($css, Kirki_Output_CSS::css($field));
             } else {
                 $css = Kirki_Helper::array_replace_recursive($css, Kirki_Output_CSS::css($field));
             }
         }
     }
     if (is_array($css)) {
         return Kirki_Output_CSS::styles_parse(Kirki_Output_CSS::add_prefixes($css));
     }
     return;
 }
 public function include_stylesheets()
 {
     $config = apply_filters('kirki/config', array());
     $styles = '';
     Kirki_Helper::init_filesystem();
     global $wp_filesystem;
     /**
      * Include the width CSS if necessary
      */
     if (isset($config['width'])) {
         $styles .= $wp_filesystem->get_contents(Kirki::$path . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . 'customizer-dynamic-css-width.css');
         /**
          * Replace width placeholder with actual value
          */
         $styles = str_replace('WIDTH', $config['width'], $styles);
     }
     /**
      * Include the color modifications CSS if necessary
      */
     if (false !== $this->color_back && false !== $this->color_font) {
         $styles .= $wp_filesystem->get_contents(Kirki::$path . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . 'customizer-dynamic-css-colors.css');
     }
     /**
      * Include generic CSS for controls
      */
     $styles .= $wp_filesystem->get_contents(Kirki::$path . DIRECTORY_SEPARATOR . 'assets' . DIRECTORY_SEPARATOR . 'css' . DIRECTORY_SEPARATOR . 'customizer-dynamic-css.css');
     return $styles;
 }
Beispiel #5
0
 /**
  * Get the value of an option from the db.
  *
  * @var 	string	the ID of the configuration corresponding to this field
  * @var		string	the field_id (defined as 'settings' in the field arguments)
  *
  * @return 	mixed 	the saved value of the field.
  *
  */
 public static function get_option($config_id = '', $field_id = '')
 {
     /**
      * Make sure value is defined
      */
     $value = '';
     /**
      * This allows us to skip the $config_id argument.
      * If we skip adding a $config_id, use the 'global' configuration.
      */
     if ('' == $field_id && '' != $config_id) {
         $field_id = $config_id;
         $config_id = 'global';
     }
     /**
      * If $config_id is empty, set it to 'global'.
      */
     $config_id = '' == $config_id ? 'global' : $config_id;
     if ('theme_mod' == self::$config[$config_id]['option_type']) {
         /**
          * We're using theme_mods.
          * so just get the value using get_theme_mod
          */
         $value = get_theme_mod($field_id, self::$fields[$field_id]['default']);
         /**
          * If the field is a background field, then get the sub-fields
          * and return an array of the values.
          */
         if ('background' == self::$fields[$field_id]['type']) {
             $value = array();
             foreach (self::$fields[$field_id]['default'] as $property_key => $property_default) {
                 $value[$property_key] = get_theme_mod($field_id . '_' . $property_key, $property_default);
             }
         }
     } elseif ('option' == self::$config[$config_id]['option_type']) {
         /**
          * We're using options.
          */
         if ('' != self::$config[$config_id]['option_name']) {
             /**
              * Options are serialized as a single option in the db.
              * We'll have to get the option and then get the item from the array.
              */
             $options = get_option(self::$config[$config_id]['option_name']);
             if (!isset(self::$fields[$field_id]) && isset(self::$fields[self::$config[$config_id]['option_name'] . '[' . $field_id . ']'])) {
                 $field_id = self::$config[$config_id]['option_name'] . '[' . $field_id . ']';
             }
             $setting_modified = str_replace(']', '', str_replace(self::$config[$config_id]['option_name'] . '[', '', $field_id));
             /**
              * If this is a background field, get the individual sub-fields and return an array.
              */
             if ('background' == self::$fields[$field_id]['type']) {
                 $value = array();
                 foreach (self::$fields[$field_id]['default'] as $property => $property_default) {
                     if (isset($options[$setting_modified . '_' . $property])) {
                         $value[$property] = $options[$setting_modified . '_' . $property];
                     } else {
                         $value[$property] = $property_default;
                     }
                 }
             } else {
                 /**
                  * This is not a background field so continue and get the value.
                  */
                 $value = isset($options[$setting_modified]) ? $options[$setting_modified] : self::$fields[$field_id]['default'];
                 $value = maybe_unserialize($value);
             }
         } else {
             /**
              * Each option separately saved in the db
              */
             $value = get_option($field_id, self::$fields[$field_id]['default']);
             /**
              * If the field is a background field, then get the sub-fields
              * and return an array of the values.
              */
             if ('background' == self::$fields[$field_id]['type']) {
                 $value = array();
                 foreach (self::$fields[$field_id]['default'] as $property_key => $property_default) {
                     $value[$property_key] = get_option($field_id . '_' . $property_key, $property_default);
                 }
             }
         }
     }
     /**
      * reduxframework compatibility tweaks.
      * If KIRKI_REDUX_COMPATIBILITY is defined as true then modify the output of the values
      * and make them compatible with Redux.
      */
     if (defined('KIRKI_REDUX_COMPATIBILITY') && KIRKI_REDUX_COMPATIBILITY) {
         switch (self::$fields[$field_id]['type']) {
             case 'image':
                 $value = Kirki_Helper::get_image_from_url($value);
                 break;
         }
     }
     return $value;
 }
Beispiel #6
0
 /**
  * Get the value of an option from the db.
  *
  * @var 	string	the ID of the configuration corresponding to this field
  * @var		string	the field_id (defined as 'settings' in the field arguments)
  *
  * @return 	mixed 	the saved value of the field.
  *
  */
 public static function get_option($config_id = '', $field_id = '')
 {
     $value = '';
     if ('' == $field_id && '' != $config_id) {
         $field_id = $config_id;
         $config_id = 'global';
     }
     $config_id = '' == $config_id ? 'global' : $config_id;
     // Are we using options or theme_mods?
     $mode = self::$config[$config_id]['option_type'];
     // Is there an option name set?
     $option_name = false;
     if ('option' == $mode && isset(self::$config[$config_id]['option'])) {
         $option_name = self::$config[$config_id]['option'];
     }
     if ('theme_mod' == $mode) {
         // We're using theme_mods
         $value = get_theme_mod($field_id, self::$fields[$field_id]['default']);
     } elseif ('option' == $mode) {
         // We're using options
         if ($option_name) {
             // Options are serialized as a single option in the db
             $options = get_option($option_name);
             $value = isset($options[$field_id]) ? $options[$field_id] : self::$fields[$field_id]['default'];
             $value = maybe_unserialize($value);
         } else {
             // Each option separately saved in the db
             $value = get_option($field_id, self::$fields[$field_id]['default']);
         }
     }
     if (defined('KIRKI_REDUX_COMPATIBILITY') && KIRKI_REDUX_COMPATIBILITY) {
         switch (self::$fields[$field_id]['type']) {
             case 'image':
                 $value = Kirki_Helper::get_image_from_url($value);
                 break;
         }
     }
     return $value;
 }
 /**
  * Loop through all fields and create an array of style definitions.
  *
  * @static
  * @access public
  * @param string $config_id The configuration ID.
  */
 public static function loop_controls($config_id)
 {
     // Get an instance of the Kirki_Styles_Output_CSS class.
     // This will make sure google fonts and backup fonts are loaded.
     Kirki_Styles_Output_CSS::get_instance();
     $fields = Kirki::$fields;
     $css = array();
     // Early exit if no fields are found.
     if (empty($fields)) {
         return;
     }
     foreach ($fields as $field) {
         // Only process fields that belong to $config_id.
         if ($config_id != $field['kirki_config']) {
             continue;
         }
         // Only continue if field dependencies are met.
         if (!empty($field['required'])) {
             $valid = true;
             foreach ($field['required'] as $requirement) {
                 if (isset($requirement['setting']) && isset($requirement['value']) && isset($requirement['operator'])) {
                     $controller_value = Kirki_Values::get_value($config_id, $requirement['setting']);
                     if (!Kirki_Active_Callback::compare($controller_value, $requirement['value'], $requirement['operator'])) {
                         $valid = false;
                     }
                 }
             }
             if (!$valid) {
                 continue;
             }
         }
         // Only continue if $field['output'] is set.
         if (isset($field['output']) && !empty($field['output']) && 'background' != $field['type']) {
             $css = Kirki_Helper::array_replace_recursive($css, Kirki_Styles_Output_CSS::css($field));
             // Add the globals.
             if (isset(self::$css_array[$config_id]) && !empty(self::$css_array[$config_id])) {
                 Kirki_Helper::array_replace_recursive($css, self::$css_array[$config_id]);
             }
         }
     }
     $css = apply_filters('kirki/' . $config_id . '/styles', $css);
     if (is_array($css)) {
         return Kirki_Styles_Output_CSS::styles_parse(Kirki_Styles_Output_CSS::add_prefixes($css));
     }
     return;
 }
 /**
  * Build the HTTP request URL for Google Fonts.
  *
  * @return string    The URL for including Google Fonts.
  */
 public function get_google_font_uri($fonts, $weight = 400, $subset = 'all')
 {
     // De-dupe the fonts
     $allowed_fonts = $this->get_google_fonts();
     $fonts = array_unique($fonts);
     $family = array();
     // Validate each font and convert to URL format
     foreach ($fonts as $font) {
         // Verify that the font exists
         if ($this->is_google_font($font)) {
             // Build the family name and variant string (e.g., "Open+Sans:regular,italic,700")
             $family[] = $font . ':' . join(',', $this->choose_google_font_variants($font, $allowed_fonts[$font]['variants'])) . ',';
         }
     }
     // Convert from array to string
     if (empty($family)) {
         return '';
     } else {
         $request = str_replace(' ', '+', '//fonts.googleapis.com/css?family=' . implode('%7C', $family));
     }
     // load the font weight
     $weight = is_array($weight) ? implode(',', $weight) : $weight;
     $request .= trim($weight);
     // Load the font subset
     if ('all' == $subset) {
         $subsets_available = $this->get_google_font_subsets();
         // Remove the all set
         unset($subsets_available['all']);
         // Build the array
         $subsets = array_keys($subsets_available);
     } else {
         $subsets = (array) $subset;
     }
     /**
      * Sanitization: flatten the array.
      */
     $subsets = Kirki_Helper::array_flatten($subsets, 'value');
     /**
      * Append the subset string
      */
     $request .= !empty($subsets) ? '&subset=' . join(',', $subsets) : '';
     return $request;
 }
 /**
  * Refresh the parameters passed to the JavaScript via JSON.
  *
  * @access public
  */
 public function to_json()
 {
     parent::to_json();
     $this->json['icons'] = Kirki_Helper::get_dashicons();
 }