WP_Customize_Sidebar_Section
云策文档标注
概述
WP_Customize_Sidebar_Section 是 WordPress 自定义器中用于表示小工具区域(侧边栏)的特定部分类,继承自 WP_Customize_Section。它提供了管理侧边栏在自定义器中的显示和状态的方法。
关键要点
- WP_Customize_Sidebar_Section 继承自 WP_Customize_Section,专用于处理侧边栏的自定义器部分。
- 类属性包括 $type(固定为 'sidebar')和 $sidebar_id(唯一标识符)。
- 主要方法有 json() 用于向客户端 JavaScript 传递参数,以及 active_callback() 用于检查侧边栏是否在当前页面渲染。
- 自 WordPress 4.1.0 版本引入。
代码示例
class WP_Customize_Sidebar_Section extends WP_Customize_Section {
public $type = 'sidebar';
public $sidebar_id;
public function json() {
$json = parent::json();
$json['sidebarId'] = $this->sidebar_id;
return $json;
}
public function active_callback() {
return $this->manager->widgets->is_sidebar_rendered( $this->sidebar_id );
}
}
原文内容
Customizer section representing widget area (sidebar).
Description
See also
Methods
| Name | Description |
|---|---|
| WP_Customize_Sidebar_Section::active_callback | Whether the current sidebar is rendered on the page. |
| WP_Customize_Sidebar_Section::json | Gather the parameters passed to client JavaScript via JSON. |
Source
class WP_Customize_Sidebar_Section extends WP_Customize_Section {
/**
* Type of this section.
*
* @since 4.1.0
* @var string
*/
public $type = 'sidebar';
/**
* Unique identifier.
*
* @since 4.1.0
* @var string
*/
public $sidebar_id;
/**
* Gather the parameters passed to client JavaScript via JSON.
*
* @since 4.1.0
*
* @return array The array to be exported to the client as JSON.
*/
public function json() {
$json = parent::json();
$json['sidebarId'] = $this->sidebar_id;
return $json;
}
/**
* Whether the current sidebar is rendered on the page.
*
* @since 4.1.0
*
* @return bool Whether sidebar is rendered.
*/
public function active_callback() {
return $this->manager->widgets->is_sidebar_rendered( $this->sidebar_id );
}
}
Changelog
| Version | Description |
|---|---|
| 4.1.0 | Introduced. |