Can’t output do_settings_sections . Can’t understand why

From what I see, you are mixing output and the code, which is meant to prepare that output. More, the preparation is coming after the output started. Looks weird to me.

Here I updated your code, and it works OK:

/* Hook to admin_menu the yasr_add_pages function above */
add_action( 'admin_menu', 'yasr_add_pages' );

function yasr_add_pages() {

    //Add Settings Page
    add_options_page(
        'Yet Another Stars Rating: Settings', //Page Title
        __( 'Yet Another Stars Rating: Settings', 'yasr' ), //Menu Title
        'manage_options', //capability
        'yasr_settings_page', //menu slug
        'yasr_settings_page_content' //The function to be called to output the content for this page.
    );

}

add_action( 'admin_init', 'yasr_multi_form_init' );

function yasr_multi_form_init() {
    register_setting(
        'yasr_multi_form', // A settings group name. Must exist prior to the register_setting call. This must match the group name in settings_fields()
        'yasr_multi_form_data' //The name of an option to sanitize and save.
    );

    add_settings_section( 'yasr_section_id', 'Gestione Multi Set', 'yasr_section_callback', 'yasr_settings_page' );
    add_settings_field( 'yasr_field_name_id', 'Nome Set', 'yasr_nome_callback', 'yasr_settings_page', 'yasr_section_id' );
}

function yasr_section_callback() {
    echo "Descrizione sezione";
}

function yasr_nome_callback() {
    $option = get_option( 'yasr_multi_form_data' );
    $name   = esc_attr( $option['name'] );
    echo "<input type="text" name="yasr_multi_form_data[name]" value="" />";
}

/* Settings Page Content */
function yasr_settings_page_content() {
    if ( ! current_user_can( 'manage_options' ) ) {
        wp_die( __( 'You do not have sufficient permissions to access this page.', 'yasr' ) );
    }
    ?>
    <div class="wrap">
        <h2>Settings API Demo</h2>

        <form action="options.php" method="post">
            <?php
            settings_fields( 'yasr_multi_form' );
            do_settings_sections( 'yasr_settings_page' );
            submit_button( 'Salva' );
            ?>
        </form>
    </div>

<?php
} //End yasr_settings_page_content

enter image description here

Leave a Comment