I am certain it is something silly. But I can't find it and with such simple code at a loss for anything else. Having looked at many other plugins doing settings in a lot of ways can't really see how it is different from those doing similar code. This is actually the select code from WordPress Codex. After my code didn't work I went and checked the codex and tried it. The really odd thing is that occasionally WordPress saves the selection. But mostly it doesn't.
I can bypass the WordPress methods and use straight PHP, but then I learn nothing. Many plugins are bypassing the register_settings method to deal with POST and DB.
Again as last time setup as a plugin. As always your help is greatly appreciated.
<?php
/*
Plugin Name: myplug
Version: 0.1
Plugin URI: http://myplug.org
Author: ME
Description: Stupid plugin
*/
add_action('admin_init', 'myplug_register_options'); // register options for the form
add_action('admin_menu', 'myplug_admin_links'); // register admin menu hyperlinks
/** Function to register form fields **/
function myplug_register_options(){
register_setting('myplug_options_group', 'myplug_settings', 'myplug_validate');
}
/** Function to add hyperlinks to the admin menus using hooks and filters. **/
function myplug_admin_links() {
add_options_page('myplug Setup', 'myplug', 'manage_options', 'myplug', 'myplug_admin_page' ); // add link to settings page
add_filter( 'plugin_action_links', 'myplug_settings_link', 10, 2 ); // add link to plugin page
}
/** Function to create link for plugin_action_links filter **/
function myplug_settings_link($links, $file){
if ( $file == plugin_basename( dirname(__FILE__). '/myplug.php')){
$settings_link = '<a href="options-general.php?page=myplug">' .__('Settings') . '</a>';
array_unshift( $links, $settings_link ); // place before other links
}
return $links;
}
/** Validate User Input **/
function myplug_validate($input) {
$input['select_it'] = wp_filter_nohtml_kses($input['select_it']);
return($input);
}
/** Draw the Settings Page **/
function myplug_admin_page(){
?>
<div>
<h2>Options</h2>
<form method="post" action="options.php">
<?php settings_fields('myplug_options_group'); ?>
<?php $myplug_options = get_option('myplug_settings'); ?>
<select name="input[select_it]">
<option value="1" <?php selected( $input['select_it'], 1 ); ?>>1</option>
<option value="2" <?php selected( $input['select_it'], 2 ); ?>>2</option>
<option value="3" <?php selected( $input['select_it'], 3 ); ?>>3</option>
</select>
<?php submit_button(); ?>
</form>
</div>
<?php
}
?>