类文档

WP_Customize_Themes_Panel

💡 云策文档标注

概述

WP_Customize_Themes_Panel 是 WordPress 自定义器中的一个面板类,用于管理主题切换功能。它继承自 WP_Customize_Panel,专门处理主题相关的界面渲染。

关键要点

  • WP_Customize_Themes_Panel 继承自 WP_Customize_Panel,用于自定义器中的主题面板。
  • 面板类型为 'themes',自 WordPress 4.9.0 版本引入。
  • 提供两个主要方法:content_template 用于面板内容模板,render_template 用于渲染面板容器。
  • render_template 方法生成包含活动主题标题和切换按钮的定制化面板头部。

代码示例

class WP_Customize_Themes_Panel extends WP_Customize_Panel {
    public $type = 'themes';
    protected function render_template() {
        // 渲染逻辑,包括活动主题显示和切换按钮
    }
}

📄 原文内容

Customize Themes Panel Class

Description

See also

Methods

Name Description
WP_Customize_Themes_Panel::content_template An Underscore (JS) template for this panel’s content (but not its container).
WP_Customize_Themes_Panel::render_template An Underscore (JS) template for rendering this panel’s container.

Source

class WP_Customize_Themes_Panel extends WP_Customize_Panel {

/**
* Panel type.
*
* @since 4.9.0
* @var string
*/
public $type = 'themes';

/**
* An Underscore (JS) template for rendering this panel's container.
*
* The themes panel renders a custom panel heading with the active theme and a switch themes button.
*
* @see WP_Customize_Panel::print_template()
*
* @since 4.9.0
*/
protected function render_template() {
?>
<li id="accordion-section-{{ data.id }}" class="accordion-section control-panel-themes">
<h3 class="accordion-section-title">
manager->is_theme_active() ) {
echo '<span class="customize-action">' . __( 'Active theme' ) . '</span> {{ data.title }}';
} else {
echo '<span class="customize-action">' . __( 'Previewing theme' ) . '</span> {{ data.title }}';
}
?>

<button type="button" class="button change-theme" aria-label="<?php esc_attr_e( 'Change theme' ); ?>"></button>

</h3>
<ul class="accordion-sub-container control-panel-content"></ul>
</li>

<li class="panel-meta customize-info accordion-section <# if ( ! data.description ) { #> cannot-expand<# } #>">
<button class="customize-panel-back" tabindex="-1" type="button"><span class="screen-reader-text">

</span></button>
<div class="accordion-section-title">
<span class="preview-notice">
' . __( 'Themes' ) . '</strong>'
); // Separate strings for consistency with other panels.
?>
</span>

<# if ( data.description ) { #>
<button class="customize-help-toggle dashicons dashicons-editor-help" type="button" aria-expanded="false"><span class="screen-reader-text">

</span></button>
<# } #>

</div>

<# if ( data.description ) { #>
<div class="description customize-panel-description">
{{{ data.description }}}
</div>
<# } #>

<div class="customize-control-notifications-container"></div>
</li>
<li class="customize-themes-full-container-container">
<div class="customize-themes-full-container">
<div class="customize-themes-notifications"></div>
</div>
</li>
</pre><p class="wporg-dot-link-list"><a href="https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-customize-themes-panel.php/">View all references</a> <a href="https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/customize/class-wp-customize-themes-panel.php#L17">View on Trac</a> <a href="https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/customize/class-wp-customize-themes-panel.php#L17-L113">View on GitHub</a></p></section>

<section class="wp-block-wporg-code-reference-related" data-nosnippet="true"><h2 id="related" class="is-toc-heading wp-block-heading has-heading-5-font-size" tabindex="-1" ><a href="#related">Related</a></h2> <section style="margin-top:var(--wp--preset--spacing--20)" class="wp-block-wporg-code-table" id="uses"><figure class="wp-block-table "><table><thead><tr><th scope="col">Uses</th><th scope="col">Description</th></tr></thead><tbody><tr class=""><td><a href="https://developer.wordpress.org/reference/classes/wp_customize_panel/">WP_Customize_Panel</a><code>wp-includes/class-wp-customize-panel.php

Changelog

Version Description
4.9.0 Introduced.