Forums

WordPress code not saving options (2 posts)

  1. torvad
    Member
    Posted 1 year ago #

    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 );
    }
  2. mwaterous
    Member
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic