WordPress.org

Ready to get started?Download WordPress

Forums

Somehow my code based on Settings API doesnt work OK, can't figure out why (1 post)

  1. rreimche
    Member
    Posted 1 year ago #

    It think I do everything as it is said in descriptions and tutorials, but still I don't have any options displayed on my options page and I don't understand why.

    Well, at first at the beginning of functions.php I include the file with Settings-API-based code:

    require_once 'aboutsite.php';

    Then I add those 3:

    add_action('admin_menu', 'aboutus_menuitem');
    add_action('admin_menu','myoptions_save_settings');
    add_action('admin_init','prepare_settings');

    The I registration of settings, sections and fields:

    function prepare_settings(){
        register_setting('myoptions','myoptions');
    
        add_settings_field('aboutsite', 'Aboutsite', 'myoptions_settings_aboutsite_content', 'sinkevich','aboutsite');
    }

    Then the "main" page function:

    function aboutus_menuitem(){
        add_menu_page('About the site', 'About the site', 'read', 'aboutsite','aboutsite_page',NULL,11);
    }
    
    function aboutsite_page(){
        ?><div id="wrap">
    
        <?php if ( isset( $_GET['setting-updated'] ) ) echo '<div class="updated"><p>Options saved</p></div>';?>    
    
            <form action="admin.php?page=aboutsite" method="post">
                <?php
                    settings_fields('myoptions');
                    do_sections('myoptions');
                ?>
                <input name="myoptions_aboutsite[submit]" type="submit" class="button-primary" value="Сохранить" />
            </form>
    
        </div><?php
    
    }

    And the last, functions that do the code of the input fields, textareas, etc:

    function sinkevich_settings_aboutsite_section() {
    
    }
    
    function sinkevich_settings_aboutsite_content(){
        $options = get_option('sinkevich');
        ?>
        <textarea name="aboutsite"><?php echo $options['aboutsite']; ?></textarea>
        <?php
    }

    Then, I run the site and see a new menu page, click it and theres is no fields there. There is a form in the code generated, but there's only:

    <form action="admin.php?page=aboutsite" method="post">
                <input type="hidden" name="option_page" value="myoptions"><input type="hidden" name="action" value="update"><input type="hidden" id="_wpnonce" name="_wpnonce" value="abbb1ca570"><input type="hidden" name="_wp_http_referer" value="/wp-admin/admin.php?page=aboutsite"></form>

Topic Closed

This topic has been closed to new replies.

About this Topic