0

Добавляю подменю в меню и туда добавляю секции и в дальнейшем и поля. Но по этой же схеме не могу добавить поля не подменю, а самому меню. Не могу найти ответа на этот вопрос. Буду очень признателен

function fs_menu_page() {

    // Вывод в админпанель секций главной
    add_menu_page(
        'Секции главной',
        'Секции главной',
        'administrator',
        'sections',
        'section_menu_page_display',
        'dashicons-welcome-write-blog',
        21
    );
    
    // Подменю
    add_submenu_page(
        'sections',
        'О нас',
        'О нас',
        'administrator',
        'about_options',
        'about_options_display'
    );
    
    // Секция "О нас" левая
    add_settings_section(
        'about_left_section',
        'Левый блок с формой и полями',
        '',
        'about_options'
    );

// Не добавляет секцию на страницу

    // Секция "О нас" левая
    add_settings_section(
        'about_left_section',
        'Левый блок с формой и полями',
        '',
        'sections'
    );

}
add_action('admin_menu', 'fs_menu_page');
// Отображение главной страницы секций
function section_menu_page_display() {
    ?>
    <div class="wrap">
        <h4>Выбирете секцию</h4>
    </div>
    <?php
}

4
  • Причем секция настроек к админ-меню? В чём собсно вопрос?
    – SeVlad
    4 янв 2018 в 18:44
  • К секции добавляем поля. Но секции добавляются только на подменю, к самому меню не добавляются таким способом. Я хочу узнать способ добавления секций и полей пункту меню
    – Igor
    4 янв 2018 в 19:30
  • Меню - это ссылки на страницы, а никакие не секции. Вот что будет на этих страницах (и как что там будет работать) - это другой вопрос.
    – SeVlad
    4 янв 2018 в 20:04
  • То что вы хотите реализовать, мне кажется лучше в кастомайзере запилить. Это будет легче и удобнее. Подобный функционал можете посмотреть в бесплатной теме Modality 3 окт 2018 в 21:17

1 ответ 1

1

Регистрируете группу полей, добавляете секцию, добавляете поля и ниже вызываете их (везде есть комментарии, какие параметры нужно указать)

function register_custom_settings() {
    register_setting('custom-settings-group','header_title');
    register_setting('custom-settings-group','header_description');
    register_setting('custom-settings-group','footer_text');
    // register_setting( $option_group, $option_name, $sanitize_callback );

    add_settings_section('custom-settings','Основная информация','custom_settings','custom-settings');
    // add_settings_section( $id, $title, $callback, $page );

    add_settings_field('header_title','Заголовок','custom_header_title','custom-settings','custom-settings');
    add_settings_field('header_description','Описание','custom_header_description','custom-settings','custom-settings');
    add_settings_field('footer-text','Подвал','custom_footer_text','custom-settings','custom-settings');
    // add_settings_field( $id, $title, $callback, $page, $section, $args );
}

function custom_settings() {
    echo 'Блок с основной информацией';
}

function custom_header_title() {
    $headerTitle = esc_attr(get_option('header_title'));
    echo '<input type="text" class="regular-text code" name="header_title" value="'.$headerTitle.'" />';
    echo '<p class="description"><strong>Этот текст будет отображаться в блоке Header:</strong><br>"' . $headerTitle . '"</p>';
}

function custom_header_description() {
    $headerDescription = esc_attr(get_option('header_description'));
    echo '<input type="text" class="regular-text code" name="header_description" value="'.$headerDescription.'" />';
    echo '<p class="description"><strong>Этот текст будет отображаться в блоке Header:</strong><br>"' . $headerDescription . '"</p>';
}

function custom_footer_text() {
    $footerText = esc_attr(get_option('footer_text'));
    echo '<input type="text" class="regular-text code" name="footer_text" value="'.$footerText.'" />';
    echo '<p class="description"><strong>Этот текст будет отображаться в блоке Footer:</strong><br>"' . $footerText . '"</p>';
}

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.