Add 'Reply to <name>' button for comments

for piece of mind, could you confirm this @anon71687268

here’s the whole script - given the good advice by @anon71687268 create a folder in the /plugins directory (add-comment-reply-name or whatever) and stick this script inside (add-comment-reply-name.php) and edit the namespace entries as needed - finally, set the owner and group (chown) of both the file and folder accordingly (admin:admin in many cases), then activate in CP as any other plugin

<?php

/**
 * Plugin Name:  Comment Reply To Name
 * Plugin URI: <some URL>
 * Author Name: <name>
 * Author URI: <some URL>
 * Description: changes Reply link in comments to include the commenters name
 * Version: 0.1.0
 */

namespace Comment_Reply_To_Name;

/* die if called directly */
defined('ABSPATH') or die('No direct access!');

// original code: https://raam.org/2013/personalizing-the-wordpress-comment-reply-link/
if (! function_exists('add_comment_author_to_reply_link')) {
    function add_comment_author_to_reply_link($link, $args, $comment){
        $comment = get_comment($comment);
        // If no comment author is blank, use 'Anonymous'
        if (empty($comment->comment_author)) {
            if (!empty($comment->user_id)){
                $user=get_userdata($comment->user_id);
                $author=$user->user_login;
            } else {
                $author = __('Anonymous');
            }
        } else {
            $author = $comment->comment_author;
        }
        // If the user provided more than a first name, use only first name
        //if(strpos($author, ' ')){
        //    $author = substr($author, 0, strpos($author, ' '));
        //}
        // Replace Reply Link with "Reply to &lt;Author First Name>"
        $reply_link_text = $args['reply_text'];
        $link = str_replace($reply_link_text, "Reply to '" . $author . "'", $link);
        return $link;
    }
    add_filter('comment_reply_link', __NAMESPACE__.'add_comment_author_to_reply_link', 10, 3);
}
3 Likes