Modify column_author in WP_Comments_List_Table

Is it possible to modify the values in the author column in the edit-comments.php section of the backend? A hook? I want to change the mailto field for the commenter’s email to include a subject and body. I am pretty sure I found where someone had said there was a way a couple of months ago, but I cannot find it again.

1
1

This is how the email part is displayed by the WP_Comments_List::column_author() method:

/* This filter is documented in wp-includes/comment-template.php */
$email = apply_filters( 'comment_email', $comment->comment_author_email, $comment );

if ( ! empty( $email ) && '@' !== $email ) {
    printf( '<a href="https://wordpress.stackexchange.com/questions/258903/%1$s">%2$s</a><br />', esc_url( 'mailto:' . $email ), esc_html( $email ) );
}

so you’re most likely looking for the comment_email filter.

Update:

Here’s a hack to add a subject and body to the mailto part:

add_filter( 'comment_email', function( $email )
{
    // Target the edit-comments.php screen
    if( did_action( 'load-edit-comments.php' ) )
        add_filter( 'clean_url', 'wpse_258903_append_subject_and_body' );       

    return $email;
} );

function wpse_258903_append_subject_and_body( $url )
{
    // Only run once
    remove_filter( current_filter(), __FUNCTION__ );

    // Adjust to your needs:
    $args = [ 'subject' => 'hello', 'body' => 'world' ];

    // Only append to a mailto url
    if( 'mailto' === wp_parse_url($url, PHP_URL_SCHEME )  )
        $url .= '?' . build_query( $args );

    return esc_url( $url );
}

Note that this targets the first esc_url() after each time the comment_email filter is applied, on the edit-comments.php page.

We added a mailto check to make sure it’s for the email part.

Leave a Comment