how do you get the settings API to save options that are in an array structure like this:
$array = array (
array(
'id'=> '1',
'name'=> 'tom',
'pageurl'=> 'someurl',
'notes'=> 'someNotes'
)
array(
'id'=>'2',
'name'=>'harry',
'pageurl'=>'someotherurl',
'notes'=>'anothernote'
)
);
This array gets data sets added to and deleted from it by the user. The wp_list_table class I am using had its option set up the same way and I need to be able to edit those values later without having to delete the whole data set of the array I need to change and then recreating it. I have tried presscoders example and ozh sample options solutions with no success. I am trying to update the name field in the array of arrays. Only reason I am using this array structure is because of the wp list table.
About to pull my hair out trying to get this to work.
Here is what I have tried:
add_action('admin_init', 'ozh_sampleoptions_init' );
add_action('admin_menu', 'ozh_sampleoptions_add_page');
// Init plugin options to white list our options
function ozh_sampleoptions_init(){
register_setting( 'ozh_sampleoptions_options', 'fp_options', 'ozh_sampleoptions_validate' );
}
// Add menu page
function ozh_sampleoptions_add_page() {
add_options_page('Ozh\'s Sample Options', 'Sample Options', 'manage_options', 'ozh_sampleoptions', 'ozh_sampleoptions_do_page');
}
// Draw the menu page itself
function ozh_sampleoptions_do_page() {
?>
<div class="wrap">
<h2>Ozh's Sample Options</h2>
<form method="post" action="options.php">
<?php settings_fields('ozh_sampleoptions_options'); ?>
<?php $options = get_option('fp_options'); ?>
<table class="form-table">
<tr valign="top"><th scope="row">Tab Name</th>
<td><input type="text" name="ozh_sample[name]" size="75" value="<?php echo $options[0]['name']; ?>" /></td>
</tr>
</table>
<p class="submit">
<input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
</p>
</form>
</div>
<?php
}
// Sanitize and validate input. Accepts an array, return a sanitized array.
function ozh_sampleoptions_validate($input) {
// Say our option must be safe text with no HTML tags
$input[0]['name'] = wp_filter_nohtml_kses($input['name']);
return $input;
}