• I would like all wordpress roles (eg contributor/author) to be able to edit post in draft status only. For the other statuses, I want to keep the standard permissions.

    Can I do this easily with a hook ?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    I’ve not tried this, but it looks like it would work. Use the ‘replace_editor’ filter. Its purpose is to allow plugins to invoke a custom editor instead of the default block editor. Except in this case if the post isn’t meant to be edited by the current user, your replacement “editor” could be in the form of an error message box or something. Return true from the filter callback to suppress loading of the default editor.

    The issue is without an editor, other aspects of the post are still changeable. For best security, those avenues should be cut off as well. It’s generally simple to prevent changes after they’re submitted. Not the best UX though. Better would be to prevent submitting in the first place, but altering back end functionality can get pretty tricky. I’ve resorted in the past to simply hiding the elements with CSS, with the after-submittal hooks as backup for those that know how to find hidden elements.

    There are a few membership type plugins that let you further restrict who does what. I’m unsure if any meet your specific need. Even if not, their source code could serve as guidance in how to prevent edit screen access. You’d just need to alter the criteria used.

    Thread Starter davidwd

    (@davidwd)

    The plugins which allows managing user permissions not corresponging to my need. For sure I can give the permission edit_others_posts to any roles, but on my side I want to give “edit_others_posts” to contributor role but only for posts which are “draft” status.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘how to give edit permission to all roles but only for a particular post status?’ is closed to new replies.