Per default wp_list_comments()
calls the class Walker_Comment
. Its method start_el()
calls edit_comment_link()
and here we find a filter for your question: It is called 'edit_comment_link'
and it passes two variables, the link text and the comment ID, which we can use.
The URLs to mark a comment as spam or to delete it are:
wp-admin/comment.php?c=1&action=cdc&dt=spam
for spam, andwp-admin/comment.php?c=1&action=cdc
for deletion.
We can add a parameter redirect_to=
to send us back to the post after the comment was trashed.
Here is a sample plugin I just hacked together (GitHub address):
<?php # -*- coding: utf-8 -*-
/**
* Plugin Name: T5 Comment moderation links
* Version: 2012.06.04
* Author: Thomas Scholz <[email protected]>
* Author URI: http://toscho.de
* License: MIT
* License URI: http://www.opensource.org/licenses/mit-license.php
*/
if ( ! function_exists( 't5_comment_mod_links' ) )
{
add_filter( 'edit_comment_link', 't5_comment_mod_links', 10, 2 );
/**
* Adds Spam and Delete links to the Sdit link.
*
* @wp-hook edit_comment_link
* @param string $link Edit link markup
* @param int $id Comment ID
* @return string
*/
function t5_comment_mod_links( $link, $id )
{
$template=" <a class="comment-edit-link" href="https://wordpress.stackexchange.com/questions/54116/%1$s%2$s">%3$s</a>";
$admin_url = admin_url( "comment.php?c=$id&action=" );
// Mark as Spam.
$link .= sprintf( $template, $admin_url, 'cdc&dt=spam', __( 'Spam' ) );
// Delete.
$link .= sprintf( $template, $admin_url, 'cdc', __( 'Delete' ) );
// Approve or unapprove.
$comment = get_comment( $id );
if ( '0' === $comment->comment_approved )
{
$link .= sprintf( $template, $admin_url, 'approvecomment', __( 'Approve' ) );
}
else
{
$link .= sprintf( $template, $admin_url, 'unapprovecomment', __( 'Unapprove' ) );
}
return $link;
}
}
Screenshot with TwentyEleven (order reversed by the stylesheet):