How To Add Settings To Your Options Pages In WordPress

<?php

add_action('admin_menu', 'custom_menu');	

function custom_menu() {

	add_submenu_page(
		'edit.php?post_type=custom_questions', 
		'Custom Settings',
		'Custom Settings', 
		'edit_posts', 
		basename(__FILE__), 
		'custom_settingspage'
	);

	//call register settings function
	add_action( 'admin_init', 'custom_settings');
}

function custom_settings() {
	//register our settings
	register_setting( 'custom-sgroup', 'custom_setting1' );
		
}

function custom_settingspage() {
	
	if (!current_user_can('manage_options'))  {
	    wp_die( __('You do not have sufficient privileges to access this page.')    );
	}
	
	$custom_setting1		= esc_attr( get_option('custom_setting1') );
	$custom_setting2		= esc_attr( get_option('custom_setting2') );
	
	?>
	
	<div class="wrap">
	
			<form method="post" action="options.php">
			    <?php settings_fields( 'custom-sgroup' ); ?>
			    <?php do_settings_sections( 'custom-sgroup' ); ?>
			    <div id="settings_panel">
				    <table class="form-table">
				        <tr valign="top">
					       <th scope="row">Checkbox Input</th>
							<td>
								<label style="padding-right: 10px">
									<input type="checkbox" id="custom_setting1" name="custom_setting1" value="true" <?php echo ($custom_setting1 == 'true') ? 'checked' : 'unchecked'; ?>>
								</label>
							</td>
				        </tr>
				         <tr valign="top">
					       <th scope="row">Text Input</th>
							<td>
								<label style="padding-right: 10px">
									<input type="text" id="custom_setting2" name="custom_setting2" value="<?php echo $custom_setting1; ?>">
								</label>
							</td>
				        </tr>
				       
				      
				        <tr>
				        	<td></td>
				        	<td><?php submit_button('Save'); ?></td>
				        </tr>
				    </table>
			    </div>
			</form>
			
	</div>
	
<?php }