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)
Viewing 1 replies (of 1 total)
- The topic ‘WordPress code not saving options’ is closed to new replies.