title: Prevent Wordpress settings save - validation
body: <p><strong>My function for validation:</strong> </p>
  
  <pre><code> function my_plg_validate_options( $input ) {
  
    $valid = array();
  
    if ( is_numeric( $input['num_tags'] ) )
          $valid['num_tags'] = $input['num_tags'];
    else
          add_settings_error('my_plg_validate_num_tags_field','my_plg_validate_num_tags_error','Incorrect value entered!','error');
  
  
    if(!empty($valid))
    {
      return $valid;
    }
  
  }
  </code></pre>
  
  <p><strong><em>EDIT</em></strong></p>
  
  <pre><code>function my_plg_options_page()
  {
    ?&gt;
    &lt;div class='wrap'&gt;
     &lt;h2&gt;Tagara | Postavke &lt;/h2&gt;
  
     &lt;form action="options.php" method="post"&gt;
  
       &lt;?php settings_fields('my_plg_options'); ?&gt;
       &lt;?php do_settings_sections('my_plg'); ?&gt;
        &lt;input name="Submit" type="submit" value="Save Changes" class="button button-primary" /&gt;
     &lt;/form&gt;
    &lt;/div&gt;
  
  
  }
  
  
  function nd_tch_tagara_admin_init(){
    register_setting( 'my_plg_options', 'my_plg_options','my_plg_validate_options' );
  
    add_settings_section( 'my_plg_main', 'Postavke plugina','my_plg_section_text', 'my_plg' );
    add_settings_field( 'my_plg_num_tags_field', 'Unesite broj tagova','my_plg_setting_input', 'my_plg', 'my_plg_main' );
  }
  </code></pre>
  
  <p>It saves, well nothing and overrides my previous value (<em>Field in database is empty)</em> if num_tags is not a number. How to prevent Wordpress to  override previous value saved in setting if validation don't pass.</p>