Change WordPress user roles and capabilities › Forums › Restrict or Permit access inside WordPress – how to › Grant separate permissions additionally to a role
- This topic has 6 replies, 2 voices, and was last updated 3 years, 11 months ago by UserRole_Klima.
-
AuthorPosts
-
02/12/2020 at 16:44 #7184UserRole_KlimaParticipant
I have a role that grants all permissions to do with events. This roles should now be granted editing permissions for specific posts (by ID). Using the “Post Edit Access” window and supplying it with the respective post ID under “with post ID (comma separated)” eliminates the role’s permissions, seemingly joining the permissions by intersection instead of union.
Help is much appreciated.03/12/2020 at 13:08 #7186VladimirKeymasterRight, “Edit access” add-on restrict all post types at once, if find at least one restriction criteria. If you need to exclude events from edit restrictions you can use custom filter ure_restrict_edit_post_type.
07/12/2020 at 10:13 #7189UserRole_KlimaParticipantThanks for the reply. Now, using your code example, how do I allow the specified role (‘editor’ in your example) to only edit posts of a specific ID?
07/12/2020 at 10:56 #7190VladimirKeymasterYou don’t need a code for this. Open ‘Users->User Role Editor’, select role, click ‘Posts Edit’ insert the list of posts ID into the ‘with post ID (comma separated)’ field.
Or, you can make it individually for selected users via user profile.07/12/2020 at 12:52 #7191UserRole_KlimaParticipantI can’t use ‘Posts Edit’ as it will restrict the role’s permissions to only the there-specified IDs. What I need is to keep all permissions of the role PLUS permissions for some post IDs.
07/12/2020 at 13:57 #7192VladimirKeymasterIf you setup the code for custom filter ure_restrict_edit_post_type (I gave the link above) to exclude events from the edit restrictions, user will have access to all events without restrictions. It does not depend from post ID list in the edit restrictions form.
You just need:
1) replace ‘editor’ with your own role ID, let it be ‘role_a’;
2) replace ‘post’ with valid custom post type for events, let it be for this example: ‘event’.
So instead ofif ( in_array( 'editor', $user->roles ) ) { if ( $post_type==='post' ) { $restrict_it = false; } }
your code will have
if ( in_array( 'role_a', $user->roles ) ) { if ( $post_type==='event' ) { $restrict_it = false; } }
In assumption that you made all correctly, you can input post ID list after that and check that all events are still available for the role.
08/12/2020 at 09:47 #7194UserRole_KlimaParticipantNow I got it, thank you.
Just as a feedback note, the permission system would be more intuitive and, frankly, more useful, if the different permissions were ORed instead of ANDed.Thank you again for your fast help.
-
AuthorPosts
- You must be logged in to reply to this topic.