I am using wp_list_comments with custom callback parameter to customize how comments will be displayed.

I am using edit_comment_link (inside callback function!) to get comment author a possibility to edit their comments.

<?php edit_comment_link(); ?>

However the link appears only for admins and not for comment author!


First of all, you don't want unregistered users to be able to edit comments, because you have no way of knowing whether they are who they say they are. So, this can only be made to work for registered users.

As you can see from roles and capabilities only editors and up can moderate comments. You can give this capability to others, however, using code like this:

Update Using edit_comment is better than moderate_comments, which would be too broad for your purpose, I guess.

function wpse250786_add_cap() {
        $role = get_role( 'contributor' );
        $role->add_cap( 'edit_comment' );
add_action( 'admin_init', 'wpse250786_add_cap');
  • Applying this code will allow every user to change any comment. Is it possible to let only comment author a right to change his comment? – CMTV Dec 30 '16 at 14:28
  • By checking the current user you can assuret the link is only generated for the author. Also you can use it to prevent acces to the edit page for other comments. – cjbj Dec 30 '16 at 14:55
  • Thank you. One more question. Applying code above will add a theoretical possibility for everyone to edit comments. What if there is a way to edit comments without edit_comment_link (some kind of exploit)? – CMTV Dec 30 '16 at 15:00
  • I updated the answer, changing the capacity to edit_comment, which would have been better anyway. If you're unsure you might try a plugin like this one: wordpress.org/plugins/simple-comment-editing – cjbj Dec 31 '16 at 10:09
  • this code doesn't seem to work. I placed it in functions and display edit link using edit_comment_link() but still only I as admin can see it. Comment author can't. – CMTV Dec 31 '16 at 15:59

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.