Change WordPress user roles and capabilities › Forums › Restrict or Permit access inside WordPress – how to › How to allow a user role to see and edit others posts?
Tagged: cpt by role, list post by role
- This topic has 4 replies, 2 voices, and was last updated 6 years ago by jeffersondevasconcelos.
-
AuthorPosts
-
24/12/2018 at 20:25 #5360jeffersondevasconcelosParticipant
Well,
I have a CPT ‘x’.
For the user group with role A, I want it NOT be possible see/edit others post (X).
For the user group with role B, I want it be possible see/edit others post (X) where the owner have role B (same role) – posts where owner have role A not could be displayed here.
27/12/2018 at 14:56 #5363VladimirKeymasterHi,
1) role A: Edit restrictions add-on has “Own data only” option. It hides posts created by other authors from the current user at wp-admin posts list page.
2) role B: There is no criterion for edit restrictions by the role of authors. It’s possible to use tags or categories though. This post may give a starting point.
27/12/2018 at 19:37 #5364jeffersondevasconcelosParticipantVladimir,
thank you for your response. But this not work for me. I have a group of people that need to access the posts by role. Are the employees of a company. But, into this site is possible that exists posts created by other persons (out of company) that uses another role profile.
So, if your plugin no have this feature, may be a good idea to do because groups os users could share each other some posts, as in my case.
If you have another suggestion of how to do it, please, share.
29/12/2018 at 03:58 #5367VladimirKeymasterHi,
try this code:
add_filter('ure_post_edit_access_authors_list', 'ure_restrict_authors_list'); function ure_restrict_authors_list($authors) { $role = 'author'; $user = wp_get_current_user(); if (!in_array($role, $user->roles)) { return $authors; } $args = array( 'role' => $role ); $wp_user_search = new WP_User_Query( $args ); $users = $wp_user_search->get_results(); $ids = array(); foreach( $users as $user ) { $ids[] = $user->ID; } $ids_str = implode( ',', $ids ); $authors = URE_Utils::concat_with_comma( $authors, $ids_str ); return $authors; }
Replace ‘author’ role with your role id, like ‘role_b’. Do not forget to add ‘edit_others_posts’ capability to role_b role in order it can edit posts from other authors. Only posts from users with role_b role will be available for editing for any user with role_b role with this code applied.
29/12/2018 at 13:25 #5368jeffersondevasconcelosParticipantThank you Vladimir! Works fine!
-
AuthorPosts
- You must be logged in to reply to this topic.