Forums

[resolved] Error: options page not found. - Please help to figure out (4 posts)

  1. Abooze
    Member
    Posted 9 months ago #

    I'm trying to create an admin menu for my theme using the add_menu_page() function. It seems somewhat okay but when I save the option, I'm getting a new page with the error message: "Error: options page not found.".
    Please help me to figure out what I made mistake. Below is the full code of neo-settings.php (which is included through the functions.php). Thanks in advance :)

    <?php
    class abooze
    {
        function abooze()
        {
            add_action('admin_menu', array(&$this, 'my_admin_menu'));
        }
    
        function my_admin_menu()
        {
          	add_menu_page('Neotone framework options', 'Neotone', 'add_users','neo_options', array(&$this,'overview'), get_bloginfo("template_url") .'/images/icon.png');
        }
        function overview()
        {
    
    // here is the code for creating my option field
    add_action( 'admin_init', 'register_mysettings' );
    
    function register_mysettings() {
      register_setting( 'myoption-group', 'my_option_name' );
    }
    ?>
    
    <div class="wrap">
    <h2> Theme Option Panel</h2>
        <form method="post" action="options.php">
            <?php settings_fields( 'myoption-group' ); ?>
            <input type="text" name="my_option_name" size="80" value="<?php echo get_option('my_option_name'); ?>" />
            <p class="submit">
            <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
            </p>
        </form>
    </div>
    
    <?php 
    
      }
    }
    $abooze_object = &new abooze();
    ?>
  2. Peter Butler
    Member
    Posted 9 months ago #

    I'm guessing the problem is that you're sending the form to "options.php" in the forms action attribute.

    If you leave this blank, the form will be posted to the same page, which should work. A better option would probably be to set that action specifically to the url of your plugins option page (I'm not positive off the top of my head how that url will be structured, but you should be able to copy it from the url bar when you visit your options page). Just take it from "options.php", and include the rest.

  3. keesiemeijer
    moderator
    Posted 9 months ago #

    From the codex register settings:

    if the page/form display but you receive the error "Error: Options page not found" when attempting to submit the form it actually means the options themselves were not found. register_setting() failed (i.e. $option_group and/or $option_name do not exist or do not match), WordPress doesn't know what settings to update, and those settings were not added to the whitelist of options this options group is allowed save.

  4. Abooze
    Member
    Posted 9 months ago #

    Thank you Peter Butler and keesiemeijer.
    I fixed the problem by just re-writing the above code as follows, and now it works lovely ;)

    <?php
    
    add_action('admin_menu', 'my_admin_menu');
    
    function my_admin_menu() {
        add_menu_page('Neotone framework options', 'Neotone', 'add_users','neo_options', 'overview', get_bloginfo("template_url") .'/images/icon.png');
    	add_action( 'admin_init', 'register_mysettings' ); //call register settings function
     }
    
    function register_mysettings() {
    	register_setting( 'myoption-group', 'my_option_name' );
     } 
    
    function overview() { ?>
    
    <div class="wrap">
    <h2> Theme Option Panel</h2>
        <form method="post" action="options.php">
            <?php settings_fields( 'myoption-group' ); ?>
            <input type="text" name="my_option_name" size="80" value="<?php echo get_option('my_option_name'); ?>" />
            <p class="submit">
            <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
            </p>
        </form>
    </div>
    
    <?php } ?>

    I just threw out the implementation using a strict OOP concept here. :)

Reply

You must log in to post.

About this Topic