Last active
August 29, 2015 14:15
-
-
Save annalinneajohansson/4c681f99da54286221a2 to your computer and use it in GitHub Desktop.
Seriously... Can anyone see why my do_settings_sections fails to print? I'm blind, appearantly. *scratches head* #wordpress #do_settings_sections
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| define( 'MENU_SLUG', 'pinboard-hearts-wp' ); | |
| add_action( 'admin_menu', 'pinbheartswp_admin_menu', 10 ); | |
| function pinbheartswp_admin_menu() { | |
| /* | |
| add_options_page( $page_title, $menu_title, $capability, $menu_slug, $function); | |
| */ | |
| add_options_page( __('Pinboard ♥ WordPress Options', 'pinbheartswp' ), __('Pinboard ♥ WP', 'pinbheartswp' ), 'manage_options', MENU_SLUG, 'pinboard_hearts_wordpress_options' ); | |
| } | |
| add_action( 'admin_init', 'pinbheartswp_admin_init' ); | |
| function pinbheartswp_admin_init() { | |
| /* | |
| * http://codex.wordpress.org/Function_Reference/register_setting | |
| * register_setting( $option_group, $option_name, $sanitize_callback ); | |
| * The second argument ($option_name) is the option name. It’s the one we use with functions like get_option() and update_option() | |
| * */ | |
| # With input validation: | |
| # register_setting( 'my-settings-group', 'pinbheartswp-settings', 'pinbheartswp_settings_validate_and_sanitize' ); | |
| register_setting( 'pinbheartswp-settings-group', 'pinbheartswp-settings' ); | |
| /* | |
| * http://codex.wordpress.org/Function_Reference/add_settings_section | |
| * add_settings_section( $id, $title, $callback, $page ); | |
| * */ | |
| add_settings_section( 'section-settings', __( 'Settings', 'pinbheartswp' ), 'section_settings_callback', MENU_SLUG ); | |
| add_settings_section( 'section-links', __( 'Links', 'pinbheartswp' ), 'section_links_callback', MENU_SLUG ); | |
| # add_settings_section( 'section-notes', __( 'Notes', 'pinbheartswp' ), 'section_notes_callback', MENU_SLUG ); | |
| /* | |
| * http://codex.wordpress.org/Function_Reference/add_settings_field | |
| * add_settings_field( $id, $title, $callback, $page, $section, $args ); | |
| * */ | |
| } | |
| /* | |
| * THE ACTUAL PAGE | |
| * */ | |
| function pinboard_hearts_wordpress_options() { | |
| ?> | |
| <div class="wrap"> | |
| <h2><?php _e('Pinboard ♥ WordPress Options', 'pinbheartswp'); ?></h2> | |
| <form action="options.php" method="POST"> | |
| <?php settings_fields('pinbheartswp-settings-group'); ?> | |
| <?php do_settings_sections( MENU_SLUG ); ?> | |
| <?php submit_button(); ?> | |
| </form> | |
| </div> | |
| <?php } | |
| /* | |
| * THE SECTIONS | |
| * Hint: You can omit using add_settings_field() and instead | |
| * directly put the input fields into the sections. | |
| * */ | |
| function section_settings_callback() { | |
| $settings = (array) get_option( 'pinbheartswp-settings' ); | |
| _e( 'Some help text regarding the section goes here.' ); | |
| echo "<p>"; | |
| $field = "pinboard_api_key"; | |
| echo "<input type='text' name='pinbheartswp-settings[$field]' value='$value' />"; | |
| echo "</p>"; | |
| } | |
| function section_links_callback() { | |
| $settings = (array) get_option( 'pinbheartswp-settings' ); | |
| _e( 'Some help text regarding the section goes here.' ); | |
| echo "<p>"; | |
| $field = "pinboard_api_key"; | |
| echo "<input type='text' name='pinbheartswp-settings[$field]' value='$value' />"; | |
| echo "</p>"; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fixed: https://gist.github.com/lolitaloco/4c681f99da54286221a2/revisions
I was sending settings field id into do_settings_sections instead of the page it belongs to (constant MENU_SLUG in my code).