1

Having a lot of trouble with this config page. I have followed the documentation (which was sparse) and done a bit of searching for help.

My problem is simple, my config options aren't being created or saved. Any help would be much appreciated!

Here's the general set-up:

    public $view;

    function __construct()
    {
        $this->view = new My_View;
        // hook the settings menu
        add_action('admin_menu', array($this, 'index'));
        // hook the settings' settings
        add_action('admin_init', array($this, 'registerSettings'));
    }
    /**
     * setup the settings menu Page Title, Menu Title, Permissions, Menu Slug, View to render
     */
    public function index()
    {
        add_options_page("My Settings", "My menu", "manage_options", "My_Settings", array($this->view, 'index_view'));
    }

    public function registerSettings()
    {
        //options, name of option, validate function
        register_setting('my_general_settings', 'my_general_settings');
    }

next, the form:

public function index_view()
{ ?>

    <div class="wrap" style="display:block;">
        <h2>Settings</h2>
        <hr>

        <form method="POST" action="">
            <h3>General Settings</h3>

            <?php settings_fields('my_general_settings'); ?>
            <?php $settings = get_option('my_general_settings') ?>

            <label for="my_settings[publisher_id]">Enter your Publisher ID:</label>
            <input type="text" name="my_general_settings[publisher_id]" value="<?php echo $settings['publisher_id']?>" />
            <input type="submit" value="Save Changes" />
            <p>Forgot your ID? <a href="">Click here</a></p>
        </form>
    </div>
<?php }
3

The form action needs to point to options.php, which is WordPress' built-in handler for all settings pages:

<form method="POST" action="options.php">

This is documented fairly thoroughly on the Settings API page of the Codex.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.