Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

For some reason I am unable to save the data from my form:

add_action( 'admin_menu', 'example_menu_settings' );

/** Step 1. */
function example_menu_settings() {
    add_options_page( 'example Plugin Options', 'example', 'manage_options', 'example-settings', 'example_plugin_options' );
    add_action( 'admin_init', 'register_example_settings' );
}

/** Step 3. */
function example_plugin_options() {
    if ( !current_user_can( 'manage_options' ) )  {
        wp_die( __( 'You do not have sufficient permissions to access this page.' ) );
    }

    $client_id = get_option('example_client_id', '');
    $secret = get_option('example_secret', '');

    echo '<div class="wrap">
      <h2>example Plugin Settings</h2>
      <br><br>
        <form method="post" action="options.php">';
        settings_fields( 'example-settings-group' );
        do_settings_sections( 'example-settings-group' );
        echo '<input type="hidden" name="option_page" value="general"><input type="hidden" name="action" value="update"><input type="hidden" id="_wpnonce" name="_wpnonce" value="103f63adef"><input type="hidden" name="_wp_http_referer" value="/example-Blog/wp-admin/options-general.php">
          <table class="form-table">
            <tbody>
            <tr valign="top">
            <th scope="row"><label for="example_client_id">Client ID</label></th>
            <td><input name="example_client_id" type="text" id="example_client_id" value="' . $client_id . '" class="regular-text">
            </td>
            </tr>
            <tr valign="top">
            <th scope="row"><label for="example_secret">Secret</label></th>
            <td><input name="example_secret" type="text" id="example_secret" value="' . $secret . '" class="regular-text">
            </td>
            </tr>
            <tr><td colspan="2" class="description" style="padding: 25px 0 10px 0;">Your keys is found inside your <a href="https://example.com/user" target="_blank">example account settings</a>.</td>
            </tr>
            </tbody>
          </table>
          <br>
            <button id="example-test-connection" class="button">Test connection</button>';
            echo submit_button();
        echo '</form>
      </div>';
}

function register_example_settings() { // whitelist options
  register_setting( 'example-settings-group', 'example_client_id' );
  register_setting( 'example-settings-group', 'example_secret' );
}

Here is the error I get:

Are you sure you want to do this?

Please try again.

This is the /wp-admin/options.php page.

What am I doing wrong?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

There is a hidden field named _wpnonce in your form including hard coded value, plus another field named _wp_http_referrer. You better remove these, and let settings_fields() generate them. (it should already do so).

share|improve this answer
    
Give codex.wordpress.org/WordPress_Nonces a look. Agreed with @jörn. –  MikeNGarrett Jan 27 at 2:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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