예제 #1
0
 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 = Kirki_Field_Sanitize::sanitize_callback($args);
         foreach ($settings as $setting_key => $setting_value) {
             $default = isset($defaults[$setting_key]) ? $defaults[$setting_key] : '';
             $type = Kirki_Field_Sanitize::sanitize_type($args);
             $capability = Kirki_Field_Sanitize::sanitize_capability($args);
             $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::sanitize_callback(array('sanitize_callback' => $args['sanitize_callback'][$setting_key]));
                 }
             }
             $this->wp_customize->add_setting($setting_value, array('default' => $default, 'type' => $type, 'capability' => $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' => Kirki_Field_Sanitize::sanitize_type($args), 'capability' => Kirki_Field_Sanitize::sanitize_capability($args), 'transport' => isset($args['transport']) ? $args['transport'] : 'refresh', 'sanitize_callback' => Kirki_Field_Sanitize::sanitize_callback($args))));
     } else {
         $this->wp_customize->add_setting($args['settings'], array('default' => isset($args['default']) ? $args['default'] : '', 'type' => Kirki_Field_Sanitize::sanitize_type($args), 'capability' => Kirki_Field_Sanitize::sanitize_capability($args), 'transport' => isset($args['transport']) ? $args['transport'] : 'refresh', 'sanitize_callback' => Kirki_Field_Sanitize::sanitize_callback($args)));
     }
 }
예제 #2
0
 public function test_sanitize_capability()
 {
     $capabilities = array('activate_plugins', 'delete_others_pages', 'delete_others_posts', 'delete_pages', 'delete_posts', 'delete_private_pages', 'delete_private_posts', 'delete_published_pages', 'delete_published_posts', 'edit_dashboard', 'edit_others_pages', 'edit_others_posts', 'edit_pages', 'edit_posts', 'edit_private_pages', 'edit_private_posts', 'edit_published_pages', 'edit_published_posts', 'edit_theme_options', 'export', 'import', 'list_users', 'manage_categories', 'manage_links', 'manage_options', 'moderate_comments', 'promote_users', 'publish_pages', 'publish_posts', 'read_private_pages', 'read_private_posts', 'read');
     foreach ($capabilities as $capability) {
         $this->assertEquals($capability, Kirki_Field_Sanitize::sanitize_capability(array('capability' => $capability)));
     }
     $this->assertEquals('edit_theme_options', Kirki_Field_Sanitize::sanitize_capability(array()));
     add_filter('kirki/config', function () {
         return array('capability' => 'activate_plugins');
     });
     $this->assertEquals('activate_plugins', Kirki_Field_Sanitize::sanitize_capability(array()));
 }