WordPress settings for custom plugin

Ottopress has a pretty good tutorial for writing a wordpress plugin settings page but its a little confusing if you dont see the software flow

Here is my interpretation

 

 

 

/**
*
* Created by Urbanpixels.com
* Author: Chuck
* Copyright: 8/12]0/12 All Rights Reserved
*
*/
add_action('admin_menu', 'kpi_forum_admin_add_page');
$settings_slug = 'kpi-forum-settings'; // array catcher
$plugin_slug = 'kpi-forum';
$section_slug = 'kpi-forum-section';
add_action('admin_init', 'kpi_forum_admin_init');
function kpi_forum_admin_init(){
global $plugin_slug,$settings_slug,$section_slug;
register_setting( $settings_slug, $settings_slug, 'kpi_forum_validate' );
add_settings_section($section_slug, 'KPI Forum Settings', 'kpi_forum_section_description', $plugin_slug);
add_settings_field('kpi-forum-test-field', 'Test', 'kpi_forum_test_field', $plugin_slug, $section_slug);
add_settings_field('kpi-forum-foo-field', 'Foo', 'kpi_forum_foo_field', $plugin_slug, $section_slug);

}
function kpi_forum_admin_add_page() {
global $plugin_slug;
add_options_page('Custom Plugin Page', 'KPI Forum', 'manage_options', $plugin_slug, 'kpi_forum_form');
}
function kpi_forum_form() {
global $plugin_slug,$settings_slug;
?>
<div>
<h2>KPI Forum Settings</h2>
<form method="post" action="options.php">
<?php
settings_fields( $settings_slug );
do_settings_sections( $plugin_slug );
submit_button();
?>

</form>
</div>
<?php
}

function kpi_forum_section_description() {
?>
Some text describe section one
<?php
}

function kpi_forum_test_field() {
global $settings_slug;
$options = get_option($settings_slug);
?>
<input type="text" name="kpi-forum-settings[test]" value="<?php echo $options['test'];?>"/>
<?php
}
function kpi_forum_foo_field() {
global $settings_slug;
$options = get_option($settings_slug);
?>
<input type="text" name="kpi-forum-settings[foo]" value="<?php echo $options['foo'];?>"/>
<?php
}
function kpi_forum_validate($options) {
return $options;
}