Remove wordpress author’s capability to moderate comments on their own posts

WordPress authors have permission to edit others comments on their own post. How to disable this and still allow the authors to edit their published posts?

Related posts

2 comments

  1. From quick look at code the likely permissions check for that is edit_comment capability in edit_comment() function.

    Your options to remove that capability roughly are:

    • customize the role with plugin, for example Members
    • customize role with code, probably using remove cap functionality
    • filter thiungs around map_meta_cap or user_has_cap if you need to achieve more elaborate logic (for example denying permission in context of specific comment, rather than comments in general)

    PS not sure if this will properly omit related parts of interface, might need to deal with that separately

  2. Insert this code to your theme functions.php file:

    add_action('bulk_actions-edit-comments', 'author_remove_comments_actions');
    add_action('comment_row_actions', 'author_remove_comments_actions');
    
    function author_remove_comments_actions($actions) {
    
        if (!current_user_can('moderate_comments')) {
            if (isset($actions['delete'])) {
                unset($actions['delete']);
            }
            if (isset($actions['trash'])) {
                unset($actions['trash']);
            }
            if (isset($actions['spam'])) {
                unset($actions['spam']);
            }
            if (isset($actions['edit'])) {
                unset($actions['edit']);
            }
            if (isset($actions['quickedit'])) {
                unset($actions['quickedit']);
            }
            if (isset($actions['approve'])) {
                unset($actions['approve']);
            }
            if (isset($actions['unapprove'])) {
                unset($actions['unapprove']);
            }
        }
    
        return $actions;
    }
    

Comments are closed.