0

I'm having trouble getting a custom plugin to save options, as it cannot find options.php (and I don't know where it's supposed to be)

The full code for the plugin:

add_action( 'admin_menu', 'dotmailer_menu' );


function dotmailer_menu() {
    add_options_page( 'Dotmailer Options', 'Dotmailer Details', 'manage_options', 'dotmailer', 'dotmailer_options' );
}


function dotmailer_options() {
?>

<div class="wrap">
    <form method="post" action="options.php">
    <?php settings_fields( 'settings-group' ); ?>
    <?php do_settings_sections( 'settings-group' ); ?>

        <label>API key</label><br />
        <input type="email" name="apiemail" value="<?php echo get_option('apiemail'); ?>"><br />
        <label>Password</label><br />
        <input type="password" name="apipassword" value="<?php echo get_option('apipassword'); ?>"><br />
        <p><input type="submit" value="Save" class="button-primary" /></p>
    </form>
</div>
<?php 
}

function register_settings() {  
        register_setting('settings-group','apiemail');
        register_setting('settings-group','apipassword');
    }

When I submit the form, it simply returns an error saying that it cannot find options.php.

Am I supposed to create options.php myself? I have used similar code before without creating options.php myself and not had a problem.

1 Answer 1

2

Your register_settings function is not being called. Hook it into admin_init.

function register_settings() {  
        register_setting('settings-group','apiemail');
        register_setting('settings-group','apipassword');
    }

add_action( 'admin_init', 'register_settings' );
3
  • Just a request, please make sure that your code is properly formatted and added in either back ticks or code blocks where applicable so that others don't have to clean up after you afterwards. Thank you :-) Sep 10, 2014 at 17:42
  • Apologies for that and thanks for formatting it. Actually, I had replied from my mobile phone where I don't see any tool/option for code formatting. Is there a way so that I could do formatting and all even when accessing stackexchange site via a smartphone?
    – Domain
    Sep 10, 2014 at 18:04
  • 2
    No problem. Unfortunately not. I also post a lot from my phone. Formatting code is a shlep. What I usually do, I write my code and indent as normal. If I'm happy with the code, I go back and add 4 spaces before each line of code. 4 spaces adds a line to a code block Sep 10, 2014 at 18:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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