WordPress的自定义器隐藏自定义section?

我已经为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


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;
    }
} );

来源:

https://www.srcmini02.com/66056.html

微信公众号
手机浏览(小程序)
0
分享到:
没有账号? 忘记密码?