Wordpress Customizer скрывает пользовательский раздел? - PullRequest
0 голосов
/ 01 июня 2018

Я создал пользовательский раздел для моей темы WordPress, однако при печати каждого раздела добавляется встроенный стиль, чтобы скрыть раздел.Вот объявление раздела, регистрация пользовательского раздела и его использование:

<?php

/* Theme Test Data */
class theme_test_data extends WP_Customize_Section {
    public $type = "theme_test_data";
    public $test_url = "";
    public $test_text = "";
    public $test_link_text = "";

    public function json() {
        $json = parent::json();

        $json['test_text'] = $this->test_text;
        $json['test_link_text'] = $this->test_link_text;
        $json['test_url']  = esc_url( $this->test_url );

        return $json;
    }

    public function render_template() {?>
        <li id="accordion-section-{{ data.id }}" class="accordion-section control-section control-section-{{ data.type }}">
        <form method="POST" action="{{data.test_url}}">
            <input type="hidden" name="testdatainstall" value="1"/>
            <?php wp_nonce_field('theme.initialize');?>
            <h3 class="accordion-section-title">
                <span>{{data.test_text}}</span>
                <button type="submit" class="theme_customizer_doc_button btn">{{data.test_link_text}}</button>
            </h3>
        </form>
    </li>
    <?php }
}

//Theme registration
$wp_customize->register_section_type( 'theme_test_data' );

//Add section
$wp_customize->add_section(new theme_test_data($wp_customize, 'theme_test_data', array(
    'title'    => __('Section Title', 'theme_language'),
    'test_url'  => admin_url('edit.php'),
    'test_text' => __('Install our test data', 'theme_language'),
    'test_link_text' => __('Install', 'theme_language'),
    'priority' => 1000
)));

Однако в выводе HTML оно отображается следующим образом:

<li id="accordion-section-theme_test_data" class="accordion-section control-section control-section-theme_test_data" aria-owns="sub-accordion-section-theme_test_data" style="display: none;">
    <form method="POST" action="{hiddenforprivacy}">
        <input name="testdatainstall" value="1" type="hidden">
        <input id="_wpnonce" name="_wpnonce" value="24923e18ae" type="hidden"><input name="_wp_http_referer" value="/wp/wp-admin/customize.php?return=%2Fwp%2Fwp-admin%2Fedit.php" type="hidden">
        <h3 class="accordion-section-title">
            <span>Install our test data</span>
            <button type="submit" class="theme_customizer_doc_button btn">Install</button>
        </h3>
    </form>
</li>

У вас есть какие-либо подсказки?Я перепробовал их все: (

1 Ответ

0 голосов
/ 01 июня 2018

Раздел WordPress состоит из структуры HTML и раздела JavaScript.Я не установил раздел как всегда активный с помощью JavaScript.Я сделал следующее:

api.sectionConstructor['theme_test_data'] = api.Section.extend( {

    // No events for this type of section.
    attachEvents: function () {},

    // Always make the section active.
    isContextuallyActive: function () {
        return true;
    }
} );
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...