0

I am able to add option page to dashboard Menu and so far it works properly (at least to me) But I am not getting API Setting Saved Message after updating the page

enter image description here

add_action( 'admin_menu', 'add_acme_options_page' );
function add_acme_options_page() {

    add_menu_page(
        'Acme Options',
        'Acme Options',
        'manage_options',
        'acme-options-page',
        'display_acme_options_page'
    );

}

function display_acme_options_page() {

    echo '<h2>Acme Options</h2>';

    echo '<form method="post" action="options.php">';

    do_settings_sections( 'acme-options-page' );
    settings_fields( 'acme-settings' );

    submit_button();

    echo '</form>';

}

add_action( 'admin_init', 'acme_admin_init_one' );
function acme_admin_init_one() {

    add_settings_section(
        'acme-settings-section-one',      
        'Acme Settings Part One',         
        'display_acme_settings_message',  
        'acme-options-page'               
    );

    add_settings_field(
        'acme-input-field',        
        'Acme Input Field',        
        'render_acme_input_field',  
        'acme-options-page',        
        'acme-settings-section-one' 
    );

    register_setting(
        'acme-settings',    
        'acme-input-field'    
    );

}

function display_acme_settings_message() {
    echo "This displays the settings message.";
}

function render_acme_input_field() {

    $input = get_option( 'acme-input-field' );
    echo '<input type="text" id="acme-input-field" name="acme-input-field" value="' . $input . '" />';

}

add_action( 'admin_init', 'acme_admin_init_two' );
function acme_admin_init_two() {

    add_settings_section(
        'acme-settings-section-two',
        'Acme Settings Part Two',
        'display_another_acme_settings_message',
        'acme-options-page'
    );

    add_settings_field(
        'acme-input-field-two',
        'Acme Input Field Two',
        'render_acme_input_field_two',
        'acme-options-page',
        'acme-settings-section-two'
    );

    register_setting(
        'acme-settings',
        'acme-input-field-two'
    );

}

function display_another_acme_settings_message() {
    echo "This displays the second settings message.";
}

function render_acme_input_field_two() {

    $input = get_option( 'acme-input-field-two' );
    echo '<input type="text" id="acme-input-field-two" name="acme-input-field-two" value="' . $input . '" />';

}

Can you please let me know if I am missing a part or...?

1

You need the settings_errors(); function somewhere on your settings page:

function display_acme_options_page() {
    settings_errors();

    echo '<h2>Acme Options</h2>';      

    echo '<form method="post" action="options.php">';

    do_settings_sections( 'acme-options-page' );
    settings_fields( 'acme-settings' );

    submit_button();

    echo '</form>';

}
  • Thanks for reply Jacob, this is some how working but this time I am getting two Setting Saved Message :-) Can you please let me know why I am getting two messages now? – JJ BOBO Feb 7 '18 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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