在选项页面上更新后未收到API设置已保存确认消息

时间:2018-02-07 作者:JJ BOBO

我能够将选项页添加到仪表板菜单,到目前为止,它工作正常(至少对我来说),但我没有得到API Setting Saved Message 更新页面后

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 . \'" />\';

}
如果我缺少一个部件或…,请告诉我好吗。。。?

1 个回复
最合适的回答,由SO网友:Jacob Peattie 整理而成

你需要settings_errors(); 在设置页面的某个位置运行:

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>\';

}

结束