At the moment I’m doing
add_filter("manage_edit-comments_columns", function($columns) {
unset($columns["author"]);
$columns_one = array_slice($columns,0,1);
$columns_two = array_slice($columns,1);
$columns_one["user"] = "User";
$columns = $columns_one + $columns_two;
return $columns;
});
add_filter( 'manage_comments_custom_column', function($column, $column_id) {
echo "Test";
},10, 2 );
Is there a way to just edit the author column instead of removing and creating my own?
There is no filter for this column. So answer is ‘No’.
WP_List_Table search for method column_{something} inside class of Lister. Comments List class has column_author. So kill this column, and create filter as you do now.
I came to this question since I needed a similar thing. While an answer by qwerty-qwerty is correct, it’s correct only partially so to say. As far as I understand, author needed to change a column name, while I needed to change contents of the author column itself. So, while this is a bit different, I’ll just leave it here in case someone finds this question like I did. This also works if you need to get some additional data regarding comments which isn’t stored in meta table and isn’t not cached like said table and don’t want to do separate query for each item.
So, what you can do is hook into
the_comments
filter. This filter passes an array of ofWP_Comment_Object
instances for each comment found that matches the request. In my case, comments could be saved with name other than user’s display name, so where it was the case, I needed to get an actual display name fromwp_users
table and display it likecomment_author_from_wp_comments (display_name_from_wp_users)
. I went through array passed by the filter, figured which comments needed additional info fromwp_users
table, ran a single query to that table, then modified elements within original array with new data. Here’s a general idea of how my code works:Hopefully, someone in the future will find this useful.