Using WordPress ‘edit_comment_misc_actions’ PHP filter

The edit_comment_misc_actions WordPress PHP filter allows you to modify the miscellaneous actions section in the edit comment form sidebar.

Usage

add_filter('edit_comment_misc_actions', 'your_custom_function', 10, 2);
function your_custom_function($html, $comment) {
  // your custom code here
  return $html;
}

Parameters

  • $html (string) – The output HTML to display miscellaneous actions.
  • $comment (WP_Comment) – The current comment object.

More information

See WordPress Developer Resources: edit_comment_misc_actions

Examples

Add a custom button to the misc actions section

Add a custom button linking to an external URL.

add_filter('edit_comment_misc_actions', 'add_custom_button', 10, 2);
function add_custom_button($html, $comment) {
  $html .= '<div class="misc-pub-section">';
  $html .= '<a href="https://example.com" target="_blank" class="button">Custom Button</a>';
  $html .= '</div>';

  return $html;
}

Display the comment’s IP address

Show the IP address of the commenter in the miscellaneous actions section.

add_filter('edit_comment_misc_actions', 'display_comment_ip', 10, 2);
function display_comment_ip($html, $comment) {
  $html .= '<div class="misc-pub-section">';
  $html .= 'IP Address: <strong>' . $comment->comment_author_IP . '</strong>';
  $html .= '</div>';

  return $html;
}

Add a link to search for comments by the same author in the miscellaneous actions section.

add_filter('edit_comment_misc_actions', 'search_same_author_comments', 10, 2);
function search_same_author_comments($html, $comment) {
  $search_url = admin_url('edit-comments.php?s=' . urlencode($comment->comment_author_email) . '&mode=detail');

  $html .= '<div class="misc-pub-section">';
  $html .= '<a href="' . $search_url . '">Search Comments by This Author</a>';
  $html .= '</div>';

  return $html;
}

Display comment’s user agent

Show the user agent of the commenter in the miscellaneous actions section.

add_filter('edit_comment_misc_actions', 'display_comment_user_agent', 10, 2);
function display_comment_user_agent($html, $comment) {
  $html .= '<div class="misc-pub-section">';
  $html .= 'User Agent: <strong>' . $comment->comment_agent . '</strong>';
  $html .= '</div>';

  return $html;
}

Add a custom message based on comment status

Display a custom message in the miscellaneous actions section based on the comment’s status.

add_filter('edit_comment_misc_actions', 'display_custom_message', 10, 2);
function display_custom_message($html, $comment) {
  $message = '';

  if ($comment->comment_approved == '1') {
    $message = 'This comment has been approved.';
  } elseif ($comment->comment_approved == '0') {
    $message = 'This comment is awaiting moderation.';
  } else {
    $message = 'This comment has an unknown status.';
  }

  $html .= '<div class="misc-pub-section">';
  $html .= $message;
  $html .= '</div>';
return $html;
}

Show comment’s referrer URL

Display the referrer URL (if available) of the commenter in the miscellaneous actions section.

add_filter('edit_comment_misc_actions', 'display_comment_referrer', 10, 2);
function display_comment_referrer($html, $comment) {
$referrer = get_comment_meta($comment->comment_ID, 'referrer', true);

if (!empty($referrer)) {
$html .= '<div class="misc-pub-section">';
$html .= 'Referrer URL: <strong>' . $referrer . '</strong>';
$html .= '</div>';
}

return $html;
}

Display a link to the comment author’s website (if available) in the miscellaneous actions section.

add_filter('edit_comment_misc_actions', 'link_to_comment_author_website', 10, 2);
function link_to_comment_author_website($html, $comment) {
if (!empty($comment->comment_author_url)) {
$html .= '<div class="misc-pub-section">';
$html .= '<a href="' . esc_url($comment->comment_author_url) . '" target="_blank">Visit Author's Website</a>';
$html .= '</div>';
}

return $html;
}

Display comment’s post title

Show the title of the post the comment was made on in the miscellaneous actions section.

add_filter('edit_comment_misc_actions', 'display_comment_post_title', 10, 2);
function display_comment_post_title($html, $comment) {
$post_title = get_the_title($comment->comment_post_ID);

$html .= '<div class="misc-pub-section">';
$html .= 'Comment on: <strong>' . $post_title . '</strong>';
$html .= '</div>';

return $html;
}