类文档

WP_Widget_Area_Customize_Control

💡 云策文档标注

概述

WP_Widget_Area_Customize_Control 是 WordPress 自定义控件类,用于在小工具区域(如侧边栏)的自定义界面中管理控件。它继承自 WP_Customize_Control,提供特定于小工具区域的渲染和 JSON 数据处理功能。

关键要点

  • 继承自 WP_Customize_Control,类型为 'sidebar_widgets',用于自定义小工具区域。
  • 包含属性 $sidebar_id 来标识侧边栏 ID,支持整数或字符串类型。
  • 提供 to_json() 方法,用于将 sidebar_id 等属性传递到 JavaScript。
  • 提供 render_content() 方法,用于渲染控件内容,生成相关 HTML 和 ID。
  • 自 WordPress 3.9.0 版本引入,是自定义控件系统的一部分。

代码示例

class WP_Widget_Area_Customize_Control extends WP_Customize_Control {
    public $type = 'sidebar_widgets';
    public $sidebar_id;
    
    public function to_json() {
        parent::to_json();
        $exported_properties = array( 'sidebar_id' );
        foreach ( $exported_properties as $key ) {
            $this->json[ $key ] = $this->$key;
        }
    }
    
    public function render_content() {
        $id = 'reorder-widgets-desc-' . str_replace( array( '[', ']' ), array( '-', '' ), $this->id );
        // 渲染 HTML 内容
    }
}

📄 原文内容

Widget Area Customize Control class.

Description

See also

Methods

Name Description
WP_Widget_Area_Customize_Control::render_content Renders the control’s content.
WP_Widget_Area_Customize_Control::to_json Refreshes the parameters passed to the JavaScript via JSON.

Source

class WP_Widget_Area_Customize_Control extends WP_Customize_Control {

/**
* Customize control type.
*
* @since 3.9.0
* @var string
*/
public $type = 'sidebar_widgets';

/**
* Sidebar ID.
*
* @since 3.9.0
* @var int|string
*/
public $sidebar_id;

/**
* Refreshes the parameters passed to the JavaScript via JSON.
*
* @since 3.9.0
*/
public function to_json() {
parent::to_json();
$exported_properties = array( 'sidebar_id' );
foreach ( $exported_properties as $key ) {
$this->json[ $key ] = $this->$key;
}
}

/**
* Renders the control's content.
*
* @since 3.9.0
*/
public function render_content() {
$id = 'reorder-widgets-desc-' . str_replace( array( '[', ']' ), array( '-', '' ), $this->id );
?>
<button type="button" class="button add-new-widget" aria-expanded="false" aria-controls="available-widgets">

</button>
<button type="button" class="button-link reorder-toggle" aria-label="<?php esc_attr_e( 'Reorder widgets' ); ?>" aria-describedby="<?php echo esc_attr( $id ); ?>">
<span class="reorder"></span>
<span class="reorder-done"></span>
</button>
<p class="screen-reader-text" id="<?php echo esc_attr( $id ); ?>">

</p>
</pre><p class="wporg-dot-link-list"><a href="https://developer.wordpress.org/reference/files/wp-includes/customize/class-wp-widget-area-customize-control.php/">View all references</a> <a href="https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/customize/class-wp-widget-area-customize-control.php#L17">View on Trac</a> <a href="https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/customize/class-wp-widget-area-customize-control.php#L17-L71">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_control/">WP_Customize_Control</a><code>wp-includes/class-wp-customize-control.php

Changelog

Version Description
3.9.0 Introduced.