• HashimA

    (@kaosindustries)


    I have a user set up with the role of an Author, who needs to retain the capability of editing posts while not being able to upload files or moderate comments. I’ve added the following to my theme’s functions.php:

    $edit_admin = get_role('author');
    $edit_admin->remove_cap('upload_files');
    $edit_admin->remove_cap('moderate_comments');

    However, while the Media Library page is removed from the user’s dashboard when the upload_files capability is removed, the Comments menu item remains even when the moderate_comments capability is removed.

    I’ve noticed that the Codex says that the Comments page’s visibility is linked to the edit_posts capability, but this doesn’t make any sense to me. If I have decided to remove the moderate_comments capability from a particular user, it seems logical that I don’t want that user to continue seeing the Comments that are made, as the page is then of no use to them.

    What was the rationale of implementing the moderate_comments capability in this way, and is there any possibility of making it so that when it is explicitly removed the Comments page is also removed?

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    Comments are generally visible to the public, so there is no harm in a user seeing the comments table. They cannot do anything but look, so I don’t see the problem. Contributors cannot edit posts once published, but they can still see the posts. Similar logic I think.

    You could simply hide the menu and dashboard items that lead to comments with CSS by inserting a style block from the “wp_print_scripts” action when certain users are logged in. If they know the correct URL, they can still get there. It’s not really possible to alter the capability checked when the page is displayed, it’s hardcoded into the page.

    I suppose you could hook “admin_init” and check the requested page and the current user and simply die if the conditions are met. A terrible UX, but it would be effective in preventing access. I guess if the links were hidden and they manually typed in the URL, they shouldn’t be surprised when the request dies ??

Viewing 1 replies (of 1 total)
  • The topic ‘Remove the Comments page when removing the moderate_comments capability’ is closed to new replies.