0

A plugin with its own settings page and a single text field is rendered. When a value is entered for the field and the form is submitted, Settings saved. is rendered. Yet a query of the database wp_options table shows that no value was stored for the setting; the option name rma_base_url exists in the table

Code:

add_action('admin_menu', 'remote_member_auth_menu');

function remote_member_auth_menu() {
    add_options_page('Remote Member Auth Options', 'Remote Member Auth', 'manage_options', 'rma', 'remote_member_auth_options');
}

function remote_member_auth_options() {
    if (!current_user_can('manage_options')) {
        wp_die(__('You do not have sufficient permissions to access this page.'));
    }
    echo '<div class="wrap">' .
        '<h3>Remote Member Authnetication Settings</h3>' .
        '<form method="post" action="options.php">';
    settings_fields('rma_options');
    do_settings_sections('rma');
    submit_button('Set base url');
    echo '</form>' .
        '</div>';
}

function register_rma_settings() {
    register_setting('rma_options', 'rma_base_url');
    add_settings_section('rma_main', '', 'rma_main_settings_fn', 'rma');
    add_settings_field('rma_base_url', 'Base URL', 'rma_base_url_string', 'rma', 'rma_main');
}

add_action('admin_init', 'register_rma_settings');

function rma_base_url_string() {
    $option = get_option('rma_base_url');
    echo "<input id='rma_base_url' name='rma_options[rma_base_url]' size='40' type='text' value='{$option}' />";
}

function rma_main_settings_fn() {
    echo '';
}

1 Answer 1

0

I needed to change the name attribute of the field from name='rma_options[rma_base_url]' to name='rma_base_url'

Your Answer

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

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