Title: WordPress code not saving options
Last modified: August 19, 2016

---

# WordPress code not saving options

 *  [torvad](https://wordpress.org/support/users/torvad/)
 * (@torvad)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/wordpress-code-not-saving-options/)
 * My WP-Bit.ly installation is not working. First of all, the username and API 
   key is not saved in the database.
 * Below I’ve pasted the code that should do this, but never does. The function **
   register_setting** doesn’t call the callback function **wpbitly_options_validate**.
 * The code at the bottom is something I’ve put in myself. This is working, but 
   it’s not the proper way to do it. Is there something wrong with my installation?
   How can I fix this?
 *     ```
       function wpbitly_options_init() {
       	register_setting( 'wpbitly_admin_options', 'wpbitly_options', 'wpbitly_options_validate' );
       }
   
       function wpbitly_options_validate($options ) { 
   
       	global $wpbitly;
   
               echo 'validating!!!';
   
       	$valid = FALSE;
   
       	foreach ( $options as $key => $value )
       		$options[$key] = trim( esc_attr( urlencode( $value ) ) );
   
       	if ( ! empty( $options['bitly_username'] ) && ! empty( $options['bitly_api_key'] ) ) {
   
       		$url = sprintf( $wpbitly->url['validate'], $options['bitly_username'], $options['bitly_api_key'] );
   
       		$wpbitly_validate = wpbitly_curl( $url );
   
       		if ( is_array( $wpbitly_validate ) && $wpbitly_validate['data']['valid'] == 1 )
       			$valid = TRUE;
       	}
   
       	if ( ! in_array( $options['post_types'], array( 'post', 'page', 'any' ) ) )
       		$options['post_types'] = 'any';
   
       	if ( $valid === TRUE )
       		delete_option( 'wpbitly_invalid' );
       	else
       		update_option( 'wpbitly_invalid', 1 );
   
       	return $options;
   
       }
       ```
   
 *     ```
       $arr = $_POST['wpbitly_options'];
   
       if( !empty( $arr['bitly_username'] ) ){
       	$options['bitly_username'] = $arr['bitly_username'];
       	$options['bitly_api_key']  = $arr['bitly_api_key'];
       	$options['post_types']     = $arr['post_types'];
   
       	update_option( 'wpbitly_options', $options );
       }
       ```
   

Viewing 1 replies (of 1 total)

 *  [Mark](https://wordpress.org/support/users/delayedinsanity/)
 * (@delayedinsanity)
 * [15 years, 7 months ago](https://wordpress.org/support/topic/wordpress-code-not-saving-options/#post-1639049)
 * Which version of WP Bit.ly are you currently running? There may be a conflict
   with the way it is written and WP2.9.1 as I just tested it on my local copy of
   3.0.1 without encountering this.
 * I would suggest upgrading WordPress to 3.0.1 for starters, if you are still encountering
   the problem after this or for some reason are unable to upgrade I can install
   a local copy of 2.9.1 and test it to see if we can’t track it down and fix it.

Viewing 1 replies (of 1 total)

The topic ‘WordPress code not saving options’ is closed to new replies.

 * 1 reply
 * 2 participants
 * Last reply from: [Mark](https://wordpress.org/support/users/delayedinsanity/)
 * Last activity: [15 years, 7 months ago](https://wordpress.org/support/topic/wordpress-code-not-saving-options/#post-1639049)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
