예제 #1
0
 public function test_sanitize_default()
 {
     $this->assertEquals('<div class="foo">bar</div>', Kirki_Field::sanitize_default(array('type' => 'custom', 'default' => '<div class="foo">bar</div>')));
     $this->assertEquals('foo', Kirki_Field::sanitize_default(array('default' => 'foo')));
     $this->assertEquals(array('foo', 'bar'), Kirki_Field::sanitize_default(array('default' => array('foo', 'bar'))));
     $this->assertEquals('rgba(0,0,0,0)', Kirki_Field::sanitize_default(array('default' => 'rgba(0,0,0,0)')));
     $this->assertEquals('foo', Kirki_Field::sanitize_default(array('type' => 'text', 'default' => 'foo')));
 }
예제 #2
0
 /**
  * Create the settings and controls from the $fields array and register them.
  * @var	object	The WordPress Customizer object
  */
 public function add_fields($wp_customize)
 {
     $control_types = apply_filters('kirki/control_types', array('color' => 'WP_Customize_Color_Control', 'color-alpha' => 'Kirki_Controls_Color_Alpha_Control', 'image' => 'WP_Customize_Image_Control', 'upload' => 'WP_Customize_Upload_Control', 'switch' => 'Kirki_Controls_Switch_Control', 'toggle' => 'Kirki_Controls_Toggle_Control', 'radio-buttonset' => 'Kirki_Controls_Radio_ButtonSet_Control', 'radio-image' => 'Kirki_Controls_Radio_Image_Control', 'sortable' => 'Kirki_Controls_Sortable_Control', 'slider' => 'Kirki_Controls_Slider_Control', 'number' => 'Kirki_Controls_Number_Control', 'multicheck' => 'Kirki_Controls_MultiCheck_Control', 'palette' => 'Kirki_Controls_Palette_Control', 'custom' => 'Kirki_Controls_Custom_Control', 'editor' => 'Kirki_Controls_Editor_Control', 'select2' => 'Kirki_Controls_Select2_Control', 'select2-multiple' => 'Kirki_Controls_Select2_Multiple_Control'));
     foreach (self::$fields as $field) {
         if ('background' == $field['type']) {
             continue;
         }
         $wp_customize->add_setting(Kirki_Field::sanitize_settings($field), array('default' => Kirki_Field::sanitize_default($field), 'type' => Kirki_Field::sanitize_type($field), 'capability' => Kirki_Field::sanitize_capability($field), 'transport' => Kirki_Field::sanitize_transport($field), 'sanitize_callback' => Kirki_Field::sanitize_callback($field)));
         if (array_key_exists($field['type'], $control_types)) {
             $class_name = $control_types[$field['type']];
             $wp_customize->add_control(new $class_name($wp_customize, Kirki_Field::sanitize_id($field), Kirki_Field::sanitize_field($field)));
         } else {
             $wp_customize->add_control(new WP_Customize_Control($wp_customize, Kirki_Field::sanitize_id($field), Kirki_Field::sanitize_field($field)));
         }
     }
 }
예제 #3
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);
 }
예제 #4
0
 /**
  * Create the settings and controls from the $fields array and register them.
  * @var	object	The WordPress Customizer object
  */
 public function add_fields($wp_customize)
 {
     $control_types = self::$control_types;
     $setting_types = self::$setting_types;
     foreach (self::$fields as $field) {
         if ('background' == $field['type']) {
             continue;
         }
         if (isset($field['settings']) && is_array($field['settings'])) {
             $settings = Kirki_Field::sanitize_settings($field);
             $defaults = Kirki_Field::sanitize_default($field);
             foreach ($settings as $setting_key => $setting_value) {
                 $args = array('default' => isset($defaults[$setting_key]) ? $defaults[$setting_key] : '', 'type' => Kirki_Field::sanitize_type($field), 'capability' => Kirki_Field::sanitize_capability($field), 'transport' => Kirki_Field::sanitize_transport($field));
                 if (isset($field['sanitize_callback']) && is_array($field['sanitize_callback'])) {
                     if (isset($field['sanitize_callback'][$setting_key])) {
                         $args['sanitize_callback'] = Kirki_Field::sanitize_callback(array('sanitize_callback' => $field['sanitize_callback'][$setting_key]));
                     } else {
                         $args['sanitize_callback'] = Kirki_Field::sanitize_callback($field);
                     }
                 }
                 $wp_customize->add_setting($setting_value, $args);
             }
         }
         $setting_args = array('default' => Kirki_Field::sanitize_default($field), 'type' => Kirki_Field::sanitize_type($field), 'capability' => Kirki_Field::sanitize_capability($field), 'transport' => Kirki_Field::sanitize_transport($field), 'sanitize_callback' => Kirki_Field::sanitize_callback($field));
         if (isset($field['type']) && array_key_exists($field['type'], $setting_types)) {
             // We must instantiate a custom class for the setting
             $setting_classname = $setting_types[$field['type']];
             $setting = new $setting_classname($wp_customize, Kirki_Field::sanitize_settings($field), $setting_args);
             $wp_customize->add_setting($setting);
         } else {
             $wp_customize->add_setting(Kirki_Field::sanitize_settings($field), $setting_args);
         }
         $class_name = 'WP_Customize_Control';
         if (array_key_exists($field['type'], $control_types)) {
             $class_name = $control_types[$field['type']];
         }
         $wp_customize->add_control(new $class_name($wp_customize, Kirki_Field::sanitize_id($field), Kirki_Field::sanitize_field($field)));
     }
 }
예제 #5
0
 /**
  * Create the settings and controls from the $fields array and register them.
  * @var	object	The WordPress Customizer object
  */
 public function add_fields($wp_customize)
 {
     $control_types = apply_filters('kirki/control_types', array('code' => 'Kirki_Controls_Code_Control', 'color' => 'WP_Customize_Color_Control', 'color-alpha' => 'Kirki_Controls_Color_Alpha_Control', 'image' => 'WP_Customize_Image_Control', 'upload' => 'WP_Customize_Upload_Control', 'switch' => 'Kirki_Controls_Switch_Control', 'toggle' => 'Kirki_Controls_Toggle_Control', 'radio-buttonset' => 'Kirki_Controls_Radio_ButtonSet_Control', 'radio-image' => 'Kirki_Controls_Radio_Image_Control', 'sortable' => 'Kirki_Controls_Sortable_Control', 'slider' => 'Kirki_Controls_Slider_Control', 'number' => 'Kirki_Controls_Number_Control', 'multicheck' => 'Kirki_Controls_MultiCheck_Control', 'palette' => 'Kirki_Controls_Palette_Control', 'custom' => 'Kirki_Controls_Custom_Control', 'editor' => 'Kirki_Controls_Editor_Control', 'select2' => 'Kirki_Controls_Select2_Control', 'select2-multiple' => 'Kirki_Controls_Select2_Multiple_Control', 'dimension' => 'Kirki_Controls_Dimension_Control', 'repeater' => 'Kirki_Controls_Repeater_Control'));
     $setting_types = apply_filters('kirki/setting_types', array('repeater' => 'Kirki_Settings_Repeater_Setting'));
     foreach (self::$fields as $field) {
         if ('background' == $field['type']) {
             continue;
         }
         if (isset($field['settings']) && is_array($field['settings'])) {
             $settings = Kirki_Field::sanitize_settings($field);
             $defaults = Kirki_Field::sanitize_default($field);
             foreach ($settings as $setting_key => $setting_value) {
                 $args = array('default' => isset($defaults[$setting_key]) ? $defaults[$setting_key] : '', 'type' => Kirki_Field::sanitize_type($field), 'capability' => Kirki_Field::sanitize_capability($field), 'transport' => Kirki_Field::sanitize_transport($field));
                 if (isset($field['sanitize_callback']) && is_array($field['sanitize_callback'])) {
                     if (isset($field['sanitize_callback'][$setting_key])) {
                         $args['sanitize_callback'] = Kirki_Field::sanitize_callback(array('sanitize_callback' => $field['sanitize_callback'][$setting_key]));
                     } else {
                         $args['sanitize_callback'] = Kirki_Field::sanitize_callback($field);
                     }
                 }
                 $wp_customize->add_setting($setting_value, $args);
             }
         }
         $setting_args = array('default' => Kirki_Field::sanitize_default($field), 'type' => Kirki_Field::sanitize_type($field), 'capability' => Kirki_Field::sanitize_capability($field), 'transport' => Kirki_Field::sanitize_transport($field), 'sanitize_callback' => Kirki_Field::sanitize_callback($field));
         if (isset($field['type']) && array_key_exists($field['type'], $setting_types)) {
             // We must instantiate a custom class for the setting
             $setting_classname = $setting_types[$field['type']];
             $setting = new $setting_classname($wp_customize, Kirki_Field::sanitize_settings($field), $setting_args);
             $wp_customize->add_setting($setting);
         } else {
             $wp_customize->add_setting(Kirki_Field::sanitize_settings($field), $setting_args);
         }
         $class_name = 'WP_Customize_Control';
         if (array_key_exists($field['type'], $control_types)) {
             $class_name = $control_types[$field['type']];
         }
         $wp_customize->add_control(new $class_name($wp_customize, Kirki_Field::sanitize_id($field), Kirki_Field::sanitize_field($field)));
     }
 }