Settings API Code Not Saving Options
-
Hello everyone. I am writing a WordPress plugin that makes use of the Settings API to register a few options. When I try to save my options, they do not save. The fields are blank when the page reloads and there is no message that the options saved. I’ve been racking my brain for hours and cannot find any answers. I would be very grateful for another set of eyes to take a look and point out what I’m missing. Here is the (slightly modified) start to my code for the options page:
/**************************************** Register Settings Menu & Page ****************************************/ add_action( 'admin_menu', 'rv_admin_menu' ); function rv_admin_menu() { /** // Menu Title, Page Title, Capability, Slug, Callback Function add_theme_page( 'Misc. Options', 'Misc. Options', 'manage_options', 'rv-options-page', 'rv_options_create_page' ); **/ // Parent Slug, Page Title, Menu Title, Capability, Menu Slug, Callback Function add_submenu_page('', 'Misc. Options', 'Misc. Options', 'manage_options', 'rv-options-page', 'rv_options_create_page'); } /**************************************** Register Settings ****************************************/ add_action( 'admin_init', 'rv_admin_init' ); function rv_admin_init() { /** Add the Settings Group **/ register_setting( 'rv-options-group', 'rv-settings' ); // Option Group & Options Name /* Add Custom Footer Section & Fields */ // ID, Title, Callback, Menu Page add_settings_section( 'footer-section', 'Custom Footer', 'custom_footer_section_callback', 'rv-options-page' ); // ID, Title, Callback, Menu Page, Associated Section add_settings_field( 'custom-footer-enable', 'Enable Custom Footer', 'custom_footer_enable_callback', 'rv-options-page', 'footer-section' ); add_settings_field( 'footer-content', 'Footer Content', 'custom_footer_callback', 'rv-options-page', 'footer-section' ); /* Add Author Box Section & Fields */ add_settings_section( 'author-box', 'Author Box', 'author_box_section_callback', 'rv-options-page' ); add_settings_field( 'author-box-enable', 'Globally Enable Author Box', 'author_box_enable_callback', 'rv-options-page', 'author-box' ); add_settings_field( 'author-box-title', 'Author Box Title', 'author_box_title_callback', 'rv-options-page', 'author-box' ); } /**************************************** Footer ****************************************/ /** Custom Footer Section Intro **/ function custom_footer_section_callback() { echo "Add your footer's custom HTML."; } /* Custom Footer Enable */ function custom_footer_enable_callback() { $setting_footer_enable = get_option( 'rv-settings' ); $custom_footer_enable = esc_attr( $setting_footer_enable['footer_enable'] ); echo "<input type='checkbox' name='rv-settings[footer_enable]' value='$custom_footer_enable' />"; echo " The settings below will not work unless this option is enabled."; } /* Custom Footer Text Area */ function custom_footer_callback() { $setting_footer = get_option( 'rv-settings' ); $footer = esc_attr( $setting_footer['footer'] ); echo "<textarea rows='12' cols='100' name='rv-settings[footer]' value='$footer'></textarea>"; } /**************************************** Author Box ****************************************/ /** Author Box Section Intro **/ function author_box_section_callback() { echo "Customize the Author Box"; } /* Globally Enable Author Box on Posts */ function author_box_enable_callback() { $setting_author_box_enable = get_option( 'rv-settings' ); $enable_author_box = esc_attr( $setting_author_box_enable['enable_author_box'] ); echo "<input type='checkbox' name='rv-settings[enable_author_box]' value='$enable_author_box' />"; echo " This will globally enable the author box on Posts."; } /* Custom Author Box Title */ function author_box_title_callback() { $setting_author_box_title = get_option( 'rv-settings' ); $author_box_title = esc_attr( $setting_author_box_title['author_box_title'] ); echo "<input size='100' type='text' name='rv-settings[author_box_title]' value='$author_box_title' />"; echo "<br/> This will modify the author box title. <em>Ex: '<h2>Meet the Author</h2>'"; } /**************************************** Create Settings Page ****************************************/ function rv_options_create_page() { ?> <div class="wrap"> <h2>RV Options</h2> <form action="options.php" method="POST"> <?php settings_fields( 'rv-options-group' ); // Options Group ?> <?php do_settings_sections( 'rv-options-page' ); // Menu Page ?> <?php submit_button(); ?> </form> </div> <?php }
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Settings API Code Not Saving Options’ is closed to new replies.