This seems common but I can't seem to find a solution. Trying to avoid using a plugin because this feels straightforward. I'm looking to create three user types, I want each to be able to access certain pages on the sites (different sales pages) or allow access to a whole subdirectory or group of pages. (ideally)

What I'd like to do is something like the following:

// Create custom user role

$result = add_role( 'client', __('Sales Person'),

'read' => true, // true allows this capability
'edit_posts' => false, // Disallows user to edit their own posts
'edit_pages' => false, // Disallows user to edit pages
'edit_others_posts' => false, // Disallows user to edit others posts not just their own
'create_posts' => false, // Disallows user to create new posts
'manage_categories' => false, // Disallows user to manage post categories
'publish_posts' => false, // Disallows the user to publish, otherwise posts stays in draft mode
'edit_themes' => false, // false denies this capability. User can’t edit your theme
'install_plugins' => false, // User cant add new plugins
'update_plugin' => false, // User can’t update any plugins
'update_core' => false // user cant perform core updates

to create the role, and then specify a set of additional pages that only that can access. (no need to restrict other typical levels, editors, sub, admin etc since only admin used)

Right now the only solutions I can see is this which forces people to a specific page, which is a bit less lenient than I'd prefer but basically does what I want. Although even with this, I assume I can look in SQL DB to match the id of custom created users (I hope)

Restricting users to a specific front end page

It seems like cobbling these two together I could allow access to a certain page by checking for a a specific user role. But the downside is that I'd then have to check for the id of potentially many pages.

How to check if a user is in a specific role?

Wordpress Page Restrict

I know there there is also an option to test if a person can access a page and then deny them, but again kind of more specific then what I'm looking for. I assume there has to be some kind of way to attach $capabilities to a user where you can just list a set of pages or posts only they can access?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.