User capability for editing their own comments

So my solution may be a little hackish, but it does work. Comments can be edited indefinitely, and only by admins and the registered user that posted the comment.

Part of the issue I’m dealing with is that edit_posts only allows the author of a post to edit all its comments, not necessarily the commenters themselves. In order to allow this, you need to give your editable_commenter role the edit_others_posts capability, so that they can edit comments regardless of whether they authored the parent post. Then, you need to systematically disappear every admin option that would allow them to touch anyone else’s posts or comments.

First, remove the comment_row_actions for your editable_commenters on the Comments backend page for every comment that user didn’t author. I’m using emails to match users to comments, since it’s the least likely piece to change.

// Hide the comments row for non-admins who don't match the email
function edit_own_comments_backend($actions, $comment) {
    if(is_user_logged_in()) {
        $comment_email = get_comment_author_email($comment->comment_ID);
        $email = wp_get_current_user()->user_email;

        if ($comment_email != $email && !current_user_can('administrator')) {
            unset($actions['inline hide-if-no-js']);
            unset($actions['edit']);
            unset($actions['trash']);
            unset($actions['approve']);
            unset($actions['unapprove']);
            unset($actions['spam']);
            unset($actions['delete']);
            unset($actions['quickedit']);
            unset($actions['reply']);
        }
    }

    return $actions;
}

add_filter('comment_row_actions', 'edit_own_comments_backend', 10, 2);

In my case, the editable_commenters role is solely a commenter – they should never be able to edit, create, or delete any posts. So we take away Posts from their sidebar, and also New and Edit from the top-aligned admin bar.

// Hide the "Posts" menu item from all editable_commenters

function hide_others_posts_backend() {
    if (is_user_logged_in() && current_user_can('editable_commenters')) {
        remove_menu_page('edit.php');
    }
}

add_action('admin_menu', 'hide_others_posts_backend');

// Remove "New" and "Edit" from the admin top bar for commenters
function remove_top_admin_nodes($wp_admin_bar) {
    if (current_user_can('editable_commenter')) {
        $wp_admin_bar->remove_node('new-content');
        $wp_admin_bar->remove_node('edit');
    }   
}
add_action('admin_bar_menu', 'remove_top_admin_nodes', 999);

You also need to hide the In Response To column on the Comments backend page, since they’ll be able to click on post titles to access the edit window still, but I haven’t added that yet.

Lastly, on the post page, if you’d like to keep the Edit links but want to limit them to only the user’s posts, include this.

// Show or hide the edit link on comments if you are/aren't the author
function show_single_edit_comments($link, $comment_id, $text) {
    if(is_user_logged_in()) {
        $comment_email = get_comment_author_email($comment_id);
        $email = wp_get_current_user()->user_email;

        if ($comment_email == $email || current_user_can('administrator')) {
            return $link;
        }
        else {
            return false;
        }
    }

    return false;
}

add_filter('edit_comment_link', 'show_single_edit_comments', 10, 3);