admin管理员组

文章数量:1122846

I've created a custom role via add_role, it's in my activation hook and is being removed on deactivation, thus I'm deactivating and reactivating my plugin to see the role permission changes. I can see that the changes are appearing (I've used the User Roles and Capabilities plugin to check) but I still can't view private page and posts when logged in.

add_role( 'clerk', 'Clerk', [ 'read' => true, 'read_private_pages' => true, 'read_private_posts' => true ] );

I've even tried adding some other permissions and see straight away that the user is able to do the things so am sure that I'm adding permissions in the correct way.

So why can my Clerk user still not see private posts and pages? What am I missing, do they need some other permission in order for it to work?

I've created a custom role via add_role, it's in my activation hook and is being removed on deactivation, thus I'm deactivating and reactivating my plugin to see the role permission changes. I can see that the changes are appearing (I've used the User Roles and Capabilities plugin to check) but I still can't view private page and posts when logged in.

add_role( 'clerk', 'Clerk', [ 'read' => true, 'read_private_pages' => true, 'read_private_posts' => true ] );

I've even tried adding some other permissions and see straight away that the user is able to do the things so am sure that I'm adding permissions in the correct way.

So why can my Clerk user still not see private posts and pages? What am I missing, do they need some other permission in order for it to work?

Share Improve this question asked Apr 6, 2022 at 15:56 Kevin NugentKevin Nugent 5631 gold badge8 silver badges20 bronze badges 2
  • To be clear, you're referring to seeing private posts on the front end? read_private_posts does not grant back-end access. – vancoder Commented Apr 6, 2022 at 20:56
  • Yes, that's correct, @vancoder. I don't need them to be able to access them in the admin, just view on the front end when logged in. Right now though they return error404. – Kevin Nugent Commented Apr 7, 2022 at 10:10
Add a comment  | 

1 Answer 1

Reset to default 0

Try to add a capability after you adding a rule:

add_role( 'clerk', 'Clerk', [ 'read' => true, 'read_private_pages' => true, 'read_private_posts' => true ] );
$role = get_role( 'clerk' );
$role->add_cap( 'read_private_posts' );

Work for me

本文标签: permissionsCustom Role readprivateposts Not Working