工作示例[Update]
来自
this Answer, 由@TheDeadMedic改编,这里只显示特定
post_id
. 指向此操作的链接将插入到状态行中。
Hello World
是ID为53的帖子。
单击时,它仅在URL中显示该帖子的评论
example.com/wp-admin/edit-comments.php?comment_status=all&hello_world=1
:
add_action( \'current_screen\', \'wpse_72210_comments_exclude_lazy_hook\', 10, 2 );
/**
* Delay hooking our clauses filter to ensure it\'s only applied when needed.
*/
function wpse_72210_comments_exclude_lazy_hook( $screen )
{
if ( $screen->id != \'edit-comments\' )
return;
// Check if our Query Var is defined
if( isset( $_GET[\'hello_world\'] ) )
add_action( \'pre_get_comments\', \'wpse_63422_list_comments_from_specific_post\', 10, 1 );
add_filter( \'comment_status_links\', \'wpse_63422_new_comments_page_link\' );
}
/**
* Only display comments of specific post_id
*/
function wpse_63422_list_comments_from_specific_post( $clauses )
{
$clauses->query_vars[\'post_id\'] = 53;
}
/**
* Add link to specific post comments with counter
*/
function wpse_63422_new_comments_page_link( $status_links )
{
$count = get_comments( \'post_id=53&count=1\' );
if( isset( $_GET[\'hello_world\'] ) )
{
$status_links[\'all\'] = \'<a href="edit-comments.php?comment_status=all">All</a>\';
$status_links[\'hello\'] = \'<a href="edit-comments.php?comment_status=all&hello_world=1" class="current">Hello World (\'.$count.\')</a>\';
}
else
{
$status_links[\'hello\'] = \'<a href="edit-comments.php?comment_status=all&hello_world=1">Hello World (\'.$count.\')</a>\';
}
return $status_links;
}
有用的钩子搜索下面的钩子,它们可以在文件中找到
/wp-admin/includes/class-wp-comments-list-table.php
.
它将为您提供评论屏幕可能性的全景图。
manage_comments_nav
comment_status_links
admin_comment_types_dropdown
comment_edit_pre
comment_row_actions