I’ve customized my comment form with a new field (city, but that doesn’t really matter). I’ve hooked and filtered and added my comment metadata with add_comment_metadata.
I want to show that metadata in the Comments admin panel (wp-admin/edit-comments.php). Google searches prove fruitless.
Is this possible? If it is, how does one go about it?
I’d like to show it in the author column, but I’ll settle for viewing the metadata in the edit view for each individual comment.
To show the content on individual edit pages you need to add custom meta boxes to the comment edit page. You’ll use the key
comment
for the$page
argument ofadd_meta_box
.You’ll also probably want to be able to save changes from the admin. You can hook into
edit_comment
to do that.I wrote a tutorial about this if you’re interesting in learning more — the code snippets above are from it.
To show data in the comment list table is similar to adding custom columns to post list tables.
To make sure we get the right screen, hook into
load-edit-comments.php
, grab the current screen and then hook intomanage_{$screen->id}_columns
to add another column to the comment list table.The function you hook into
manage_{$screen->id}_columns
just needs to alter the associative array to include the column. It’s a$key => $label
pair — make sure to remember the key, we’ll use it later. Going to stick with the comment title stuff above.Finally, we need to hook into
manage_comments_custom_column
to echo out the comment title in the actual list table. This is pretty straight forward. I used a switch statement here because easily expandable to include more custom columns.Any column
$key
you added earlier will be the first argument passed into the hooked function.The code from the comment tut and the above stuff for custom list table columns is here as a plugin.