2
votes

When developing a plugin, using the Settings API do create an options page many developers get this message after saving the options and posting to "options.php"

Error: options page not found in Wordpress Plugin 

Even adding a function to register this settings like:

function pg_register_settings()
{

    add_settings_section(
        'setting_section_oauth', // ID
        'Instagram API Client Info', // Title
        array( $this, 'print_section_oauth_info' ), // Callback
        $this->plugin_slug.'-setting-admin' // Page
    );  

    add_settings_field(
        'key', // ID
        'Application Key', // Title 
        array( $this, 'field_key_callback' ), // Callback
        $this->plugin_slug.'-setting-admin', // Page
        'setting_section_oauth' // Section           
    );  

    register_setting( 'bitloom-instagram-options', 'key' );  

}

And using the code below on the form

<form method="post" action="options.php">
    <?php
    settings_fields( 'bitloom-instagram-options' );   
    do_settings_sections( 'bitloom-instagram-setting-admin' );
    submit_button(); 
    ?>
</form>

Whats is missing?

1

1 Answers

3
votes

You need to register settings with the admin_init hook, otherwise it won´t work.

add_action( 'admin_init', 'pg_register_settings' );