WP_Post_Comments_List_Table
概述
WP_Post_Comments_List_Table 是 WordPress 核心类,用于在列表表格中显示文章评论,继承自 WP_Comments_List_Table。
关键要点
- 继承自 WP_Comments_List_Table,专门处理文章评论的列表显示
- 提供自定义列信息、表格类名和显示方法
- 用于后台管理界面,支持 AJAX 操作和非安全验证
代码示例
protected function get_column_info() {
return array(
array(
'author' => __( 'Author' ),
'comment' => _x( 'Comment', 'column name' ),
),
array(),
array(),
'comment',
);
}
protected function get_table_classes() {
$classes = parent::get_table_classes();
$classes[] = 'wp-list-table';
$classes[] = 'comments-box';
return $classes;
}注意事项
- 自 WordPress 3.1.0 版本引入
- 相关文件位于 wp-admin/includes/class-wp-comments-list-table.php
- 使用 wp_nonce_field 进行安全验证,防止 CSRF 攻击
Core class used to implement displaying post comments in a list table.
Description
See also
Methods
Source
class WP_Post_Comments_List_Table extends WP_Comments_List_Table {/**
* @return array
*/
protected function get_column_info() {
return array(
array(
'author' => __( 'Author' ),
'comment' => _x( 'Comment', 'column name' ),
),
array(),
array(),
'comment',
);
}/**
* @return array
*/
protected function get_table_classes() {
$classes = parent::get_table_classes();
$classes[] = 'wp-list-table';
$classes[] = 'comments-box';
return $classes;
}/**
* @param bool $output_empty
*/
public function display( $output_empty = false ) {
$singular = $this->_args['singular'];wp_nonce_field( 'fetch-list-' . get_class( $this ), '_ajax_fetch_list_nonce' );
?>
<table class="<?php echo implode( ' ', $this->get_table_classes() ); ?>" style="display:none;">
<tbody id="the-comment-list"
<?php
if ( $singular ) {
echo " data-wp-lists='list:$singular'";
}
?>
>
display_rows_or_placeholder();
}
?>
</tbody>
</table>
</pre><p class="wporg-dot-link-list"><a href="https://developer.wordpress.org/reference/files/wp-admin/includes/class-wp-post-comments-list-table.php/">View all references</a> <a href="https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-admin/includes/class-wp-post-comments-list-table.php#L17">View on Trac</a> <a href="https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-admin/includes/class-wp-post-comments-list-table.php#L17-L77">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_comments_list_table/">WP_Comments_List_Table</a><code>wp-admin/includes/class-wp-comments-list-table.php
Core class used to implement displaying comments in a list table.
Changelog
| Version | Description |
|---|---|
| 3.1.0 | Introduced. |