I'm working on Settings API recently. Now I can add my theme options item in admin menu.I can register my settings and create my section and fields. And I think I can get the options using get_option(). But the problem is I can't find my way to implement those changes in my template file. For Example I'll create a section and field for the site owner to give her the ability to change the footer text to whatever she want. Settings and textarea field appears correctly, but how can I tell WP to change that text as the site owner edit that text? what changes do I need to my theme's footer code to achieve this goal?
I'll appreciate if you can help me on this.
Edit: My Code in functions.php :
function m3n_admin_menu_init() {
add_menu_page( 'M3N Theme Options', 'M3N Settings', 'manage_options', 'm3n-theme-options', 'm3n_menu_init' );
}
add_action( 'admin_menu', 'm3n_admin_menu_init' );
function m3n_menu_init() {
echo '<div class="wrap">';
echo '<h2>M3N Theme Settings</h2>';
echo '<form action="options.php" method="POST">';
settings_fields( 'm3n_settings_group' );
do_settings_sections( 'm3n-theme-options' );
submit_button();
echo '</form>';
echo '</div>';
}
function m3n_settings_init() {
register_setting( 'm3n_settings_group', 'm3n_settings_name' );
add_settings_section( 'section-one', 'General Settings', 'm3n_section_init', 'm3n-theme-options' );
add_settings_field( 'field-one', 'Footer Settings', 'm3n_footer_field_init', 'm3n-theme-options', 'section-one' );
}
add_action( 'admin_init', 'm3n_settings_init' );
function m3n_section_init() {
echo '<p>Enter your text for Footer</p>';
}
function m3n_footer_field_init() {
$options = get_option( 'm3n_settings_name' );
echo '<textarea name="field-one" id="field-one" rows="3" value="' . $options . '"></textarea>';
}
Code inside footer.php :
<p><?php echo get_option( 'm3n_settings_name' ); ?></p>