Sometimes you may need to restrict access to certain pages and not to the entire post type. You can do this using the post groups feature of the Toolset Access plugin.
Let’s continue with the “VIP accounts” that we created in the membership site tutorial. Our objective now is to have some pages accessible only to users with the “VIP members” role. Others will see a message explaining that these pages are for VIP members only and giving them the option to log in.
Step 1: Bringing pages under Toolset Access control
By default, WordPress pages are not managed by the Toolset Access plugin. This is the case even if the plugin is active. You must first allow Toolset Access to control your pages.
- Go to Toolset -> Access Control.
- In the Post Types tab, locate the Pages section and expand it. (Note that you can expand any post type not just pages.)
- Check the Managed by Access checkbox.
- Save your changes.
Step 2: Grouping content with the same access control
The default access settings allow anyone to access any content on the front-end. Next, we’ll create an access group for the two pages that we want to control.
- Go to Toolset -> Access Control.
- Choose the “Post Groups” tab.
- Click the “Add the first Post Group” button. A pop-up opens.
- Give a name for the group in the Group title field. We suggest calling it “VIP pages.”
- In the dropdown that appears, search for page titles you would like to assign to this group. You can also add pages, posts, or custom types to the group.
- Click the “Add Group” button to save your group.
Step 3: Determining who can access the post group
We can now control who can access the pages in this group. We want to remove the “read” privileges and display a message instead of the page content to anyone who cannot read.
- In the Post Group tab, locate the VIP pages group that you have just created.
- Click on the group name to expand it.
- In the Read column, uncheck the following roles: Premium members, Subscribers, Guest.
- Ensure the VIP member as well as other roles to which you want to assign read access to this group (i.e., Editors) are checked.
- Save your changes
After the checkboxes for certain roles are unchecked, these users can no longer see the pages in this group. When they visit any of these pages, they will receive a 404 error.
In the next step, we will replace this default “Page not found” template with a customized version that you create.
Step 4: Designing a custom template for unprivileged users
Notice the pencil icon next to every unselected checkbox (see the blue arrows in the image that follows). Click on the pencil to choose the content that these users cannot access.
If you want to display the same message for all unprivileged roles, use the global icon (red arrow).
A pop-up dialog appears that allows you to display a Content Template instead of the 404 error. Use the Views plugin to design your custom Content Template.
In our example, we use the “VIP member only” Content Template that states that the page can be accessed only by VIP members and includes the following login form.
Step 4: Excluding pages from the navigation
If you want to hide some pages from your navigation based on user roles, use the Nav Menu Roles plugin (a free plugin in the WordPress official repository).
The Nav Menu Roles plugin lets you display some of your menu items for logged-in users with roles that you choose (including the custom roles you create with Access).
The following shows how you can hide the VIP dashboard page from other users.
The following allows you to compare how the menu will appear on the front-end for VIP members and visitors.
We have restricted some WordPress pages to the VIP member role using the Post Group feature of the Toolset Access plugin. You can use the same method to restrict access to some of your WordPress posts, including posts of your Custom Post Type.
If you have any questions please not hesitate to post them on the Memebership Sites support page