后台评论列表显示当前评论ID与父级ID
我想要的效果是将两列添加到wp-admin/edit-comments.php页面,评论ID本身和它的父评论ID。如下:
add_filter( 'manage_edit-comments_columns', 'rudr_add_comments_columns' );
function rudr_add_comments_columns( $my_cols ){
$misha_columns = array(
'm_comment_id' => 'ID',
'm_parent_id' => 'Parent ID'
);
$my_cols = array_slice( $my_cols, 0, 3, true ) + $misha_columns + array_slice( $my_cols, 3, NULL, true );
return $my_cols;
}
add_action( 'manage_comments_custom_column', 'rudr_add_comment_columns_content', 10, 2 );
function rudr_add_comment_columns_content( $column, $comment_ID ) {
global $comment;
switch ( $column ) :
case 'm_comment_id' : {
echo $comment_ID;
break;
}
case 'm_parent_id' : {
echo $comment->comment_parent;
break;
}
endswitch;
}
教程结束