WordPress Plugin Development

How to Build a Plugin Settings Page With the Settings API

Build a WordPress plugin settings page with the Settings API: add_options_page(), register_setting() with sanitisation, sections and fields, rendering the form with settings_fields(), storing one array option, capability checks and validation errors.

Plugin settings page in the WordPress admin with sections, fields and a Save Changes button

The Settings API builds plugin settings pages that save securely without writing your own form handler. Add a page with add_options_page() on admin_menu; on admin_init, call register_setting() with a sanitize callback, then add_settings_section() and add_settings_field(); and in the page callback print a form posting to options.php with settings_fields() and do_settings_sections(). WordPress handles the nonce, capability check, saving and the "Settings saved" notice. Store all fields in one array option to keep the database tidy.

Step 1: Add the page

add_action( 'admin_menu', function () {
    add_options_page(
        __( 'Acme Events', 'acme-events' ),   // page title
        __( 'Acme Events', 'acme-events' ),   // menu title
        'manage_options',                      // capability
        'acme-events',                         // slug
        'acme_events_render_settings'          // callback
    );
} );

This places it under Settings. For a top-level menu, use add_menu_page(); see our custom admin page guide.

Step 2: Register the setting, sections and fields

add_action( 'admin_init', function () {
    register_setting( 'acme_events', 'acme_events_settings', array(
        'type'              => 'array',
        'sanitize_callback' => 'acme_events_sanitize',
        'default'           => array( 'per_page' => 10, 'currency' => 'USD', 'show_past' => false ),
    ) );

    add_settings_section( 'acme_events_display', __( 'Display', 'acme-events' ), '__return_false', 'acme-events' );

    add_settings_field( 'per_page', __( 'Events per page', 'acme-events' ), function () {
        $o = get_option( 'acme_events_settings' );
        printf( '<input type="number" min="1" max="50" name="acme_events_settings[per_page]" id="per_page" value="%d">', (int) $o['per_page'] );
    }, 'acme-events', 'acme_events_display', array( 'label_for' => 'per_page' ) );

    add_settings_field( 'currency', __( 'Currency', 'acme-events' ), function () {
        $o = get_option( 'acme_events_settings' );
        echo '<select name="acme_events_settings[currency]" id="currency">';
        foreach ( array( 'USD', 'EUR', 'INR' ) as $c ) {
            printf( '<option value="%1$s" %2$s>%1$s</option>', esc_attr( $c ), selected( $o['currency'], $c, false ) );
        }
        echo '</select>';
    }, 'acme-events', 'acme_events_display', array( 'label_for' => 'currency' ) );

    add_settings_field( 'show_past', __( 'Show past events', 'acme-events' ), function () {
        $o = get_option( 'acme_events_settings' );
        printf( '<input type="checkbox" name="acme_events_settings[show_past]" id="show_past" value="1" %s>', checked( ! empty( $o['show_past'] ), true, false ) );
    }, 'acme-events', 'acme_events_display', array( 'label_for' => 'show_past' ) );
} );

The label_for argument wraps the field title in a <label>, which matters for accessibility.

Step 3: Sanitise and validate

function acme_events_sanitize( $input ) {
    $clean = array();
    $clean['per_page'] = min( 50, max( 1, absint( $input['per_page'] ?? 10 ) ) );

    $currency = $input['currency'] ?? 'USD';
    if ( ! in_array( $currency, array( 'USD', 'EUR', 'INR' ), true ) ) {
        add_settings_error( 'acme_events_settings', 'currency', __( 'Unknown currency, reset to USD.', 'acme-events' ) );
        $currency = 'USD';
    }
    $clean['currency']  = $currency;
    $clean['show_past'] = ! empty( $input['show_past'] );
    return $clean;
}

Unchecked checkboxes are not submitted at all, so treat a missing key as false. Always return the full array, or missing keys disappear.

Step 4: Render the page

function acme_events_render_settings() {
    if ( ! current_user_can( 'manage_options' ) ) {
        return;
    }
    ?>
    <div class="wrap">
        <h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
        <form action="options.php" method="post">
            <?php
            settings_fields( 'acme_events' );
            do_settings_sections( 'acme-events' );
            submit_button();
            ?>
        </form>
    </div>
    <?php
}

On pages under Settings, WordPress prints saved and error notices automatically. On custom top-level pages, call settings_errors() yourself.

Common mistakes

  • Mismatched group names: the first argument of register_setting() must match settings_fields(), or you get "options page not found in the allowed options list".
  • One option per field: creates dozens of autoloaded rows. Use one array.
  • No sanitize callback: anything posted is stored.
  • Not escaping when printing values back.
  • Using manage_options for everything: consider a custom capability so shop managers or instructors can edit only what they need.

Frequently asked questions

Can I use the Settings API on a custom top-level page?

Yes. The form still posts to options.php; you just add settings_errors() to show notices.

How do I add tabs?

Use a tab query argument, render nav-tab links, and register a separate option group per tab so saving one tab does not clear another.

Should settings be autoloaded?

If you read them on most requests, yes. For large or rarely used data, pass false for autoload when you add the option.

Conclusion

Register one sanitised array option, define sections and labelled fields, and let options.php handle saving. See the Settings API handbook and the register_setting() reference. Decide where other data lives with our guide to plugin data storage, add custom user fields, and build on a custom plugin with hooks.

Need a polished settings experience for your plugin? See our plugin development service.

Save this practical guide

Add us as a preferred Google source, or ask an AI assistant to summarize this page and link back to the original guide when it is useful.

· Tutor LMS developers

Guides written and reviewed by the TutorLMS Expert development team. Every hook, function, table and setting we mention is checked against the Tutor LMS and Tutor LMS Pro source code before it is published.

Keep reading

Need a custom Tutor LMS solution?

Tell us what you are building or what is broken. A Tutor LMS developer reads every inquiry and replies with next steps and a free estimate.

Get a free Tutor LMS consultation

Tell us what you are building or fixing. A Tutor LMS developer replies with honest advice and next steps.

  • No obligation
  • Tutor LMS and Pro specialists
  • Your details stay private

This form is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.