5

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.

5

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="%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.

  • Thank you. That is helpful, but not exactly what I need. I should have clarified. I want to add a subject and body to the mailto like so: <a href="mailto:user@example.com?subject=My Subject&body=Can you read me now?"> The problem with using the comment_email filter, as I see it, is that it will change the displayed email to my nasty, long string. I would love to do this with filters/hooks, but I'm starting to think that the solution is going to be javascript based – lost.in.userspace Mar 5 '17 at 10:23
  • I updated the answer with a hack. Antother alternative is to remove the author column and add your own. Then javascript is another way. @lost.in.userspace – birgire Mar 5 '17 at 12:40
  • Wow! Thank you. I did not know about the clean_url filter. That opens a new door for me. Thank you for taking the time to lay out the code for me too. You are a big help. – lost.in.userspace Mar 6 '17 at 19:27
  • You're welcome, glad to hear it helped @lost.in.userspace – birgire Mar 6 '17 at 19:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.