Title: register_setting sanitize function is not called
Last modified: August 21, 2016

---

# register_setting sanitize function is not called

 *  [Rashed Latif](https://wordpress.org/support/users/rashedlatif/)
 * (@rashedlatif)
 * [12 years, 9 months ago](https://wordpress.org/support/topic/register_setting-sanitize-function-is-not-called/)
 * I am trying to learn how to create a plugin and in doing that i was trying to
   use register_setting function.
    When i am using it without the 3rd parameter 
   it works fine and plugin options are saved successfully in options.php.
 * But when i am trying to use 3rd parameter which is the callback function its 
   not accessing at all and at that time no options are saved as well.
 * Here is the code i am using.
 *     ```
       <?php
       /*
       Plugin Name: JW Options
       Plugin URI: knowhowto.com.au
       Description: Option Page for a Theme
       Author: Rashed Latif
       Author URI: http://knowhowto.com.au
       Version: 1.0
       */
   
       class JW_Options{
           public $options;
   
           public function __construct(){
               //delete_option('jw_plugin_options');
               $this->options = get_option('jw_plugin_options');
               $this->register_setting_and_fields();  
   
           }
   
           public static function add_menu_page(){
               add_options_page('Theme Options', 'Theme Options', 'administrator', __FILE__, array('JW_Options', 'display_options_page'));
           }
   
           public static function display_options_page(){
               ?>
               <div class="wrap">
                   <?php screen_icon(); ?>
                   <h2>My Theme Options</h2>
                   <?php print_r(get_option('jw_plugin_options'));?>
                   <form method="post" action="options.php" enctype="multipart/form-data">
                       <?php settings_fields('jw_plugin_options'); ?>
                       <?php do_settings_sections(__FILE__); ?>
   
                       <P class="submit">
                           <input name="submit" type="submit" class="button-primary" value="Save Changes" />
   
                       </P>
                   </form>
   
               </div>
   
               <?php
           }
   
           public function register_setting_and_fields(){
               register_setting('jw_plugin_options', 'jw_plugin_options', array($this, 'jw_validate_settings'));// 3rd param = optional call back function
               //register_setting('jw_plugin_options', 'jw_plugin_options');
               add_settings_section('jw_main_section', 'Main Settings', array($this, 'jw_main_section_cb'), __FILE__); // id,title of section, cb, which page?
               add_settings_field('jw_banner_heading', 'Banner Heading', array($this, 'jw_banner_heading_setting'), __FILE__, 'jw_main_section');
               add_settings_field('jw_logo', 'Your Logo', array($this, 'jw_logo_setting'), __FILE__, 'jw_main_section');
               add_settings_field('jw_color_scheme', 'Your Desired Color Scheme', array($this, 'jw_color_scheme_setting'), __FILE__, 'jw_main_section');
           }
   
           public function jw_main_section_cb(){
               //optional
           }
   
           public function jw_validate_settings($plugin_options){
               print_r($plugin_options);
           }
   
           /*
            *
            *Inputs
            *
            */
   
           // Banner Heading
           public function jw_banner_heading_setting(){
   
               echo "<input name='jw_plugin_options[jw_banner_heading]' type='text' value='{$this->options['jw_banner_heading']}' />";
               //echo "<input name='jw_plugin_options[jw_banner_heading]' type='text' value='' />";
           }
   
           public function jw_logo_setting(){
   
               echo '<input type= "file" />';
           }
   
           public function jw_color_scheme_setting(){
               $items = array('Red', 'Green', 'Blue', 'Yellow', 'Black', 'White');
               echo "<select name='jw_plugin_options[jw_color_scheme]'>";
               foreach ($items as $item){
                   $selected = ($this->options['jw_color_scheme']== $item) ? 'selected="selected"' : '';
                   echo "<option value='$item' $selected>$item</option>";
               }
               echo "</select>";
   
           }
   
       }
   
       add_action('admin_menu', function(){
           JW_Options::add_menu_page();
       });
   
       add_action('admin_init', function(){
           new JW_Options();
       });
       ```
   
 * Can anyone give any idea where i am makinf mistake??

Viewing 1 replies (of 1 total)

 *  [rerraw](https://wordpress.org/support/users/rerraw/)
 * (@rerraw)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/register_setting-sanitize-function-is-not-called/#post-4288140)
 * oh i have same problem when i use or add function in `register_settings` and 
   i create a function for the validate function my options dont save in options.
   page

Viewing 1 replies (of 1 total)

The topic ‘register_setting sanitize function is not called’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [rerraw](https://wordpress.org/support/users/rerraw/)
 * Last activity: [12 years, 2 months ago](https://wordpress.org/support/topic/register_setting-sanitize-function-is-not-called/#post-4288140)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
