php - Wordpress Customizer 隐藏自定义部分?

标签 php wordpress html wordpress-theming

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

你有什么线索吗?我都试过了:(

最佳答案

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

关于php - Wordpress Customizer 隐藏自定义部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50644874/

相关文章:

html - 单击时如何保持打开的 mdl 菜单与 html 选择?

php - 为什么在 PHP 中不推荐使用 mime_content_type()?

php preg_match 噩梦

wordpress - wordpress数据库从服务器导出并导入到本地服务器时出现404错误

php - 当有多个菜单时,丢失页面 id 在 li 的菜单上

php - Wordpress 循环不显示所有帖子

html - 是否可以为类分配和输入 ID?

html - Bootstrap Carousel 提升图像并下降

javascript - 限制可以访问页面的查看者数量

javascript - 从动态选择框构造 mySQL 查询