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.

What VIP members will see
What VIP members will see. Page includes links to other pages and resources that are available only to VIP members.

Unprivileged users will see a custom template with a message followed by a login form.
Unprivileged users will see a custom template with a message followed by a login form.

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.

  1. Go to Toolset -> Access Control.
  2. In the Post Types tab, locate the Pages section and expand it. (Note that you can expand any post type not just pages.)
  3. Check the Managed by Access checkbox.
  4. Save your changes.

Bringing pages under Toolset Access control
Bringing pages under Toolset Access control

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.

  1. Go to Toolset -> Access Control.
  2. Choose the “Post Groups” tab.
  3. Click the “Add the first Post Group” button. A pop-up opens.
  4. Give a name for the group in the Group title field. We suggest calling it “VIP pages.”
  5. 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.

    Adding new Post Group
    Adding new Post Group
  6. 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.

  1. In the Post Group tab, locate the VIP pages group that you have just created.
  2. Click on the group name to expand it.
  3. In the Read column, uncheck the following roles: Premium members, Subscribers, Guest.
  4. 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.

    Determining who can access the post group
    Determining who can access the post group
  5. 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).

Selecting a custom template for unprivileged users
Selecting a custom template for unprivileged users

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.

Example Content Template that unprivileged users see when trying to access a page with restricted access.
Example Content Template that unprivileged users see when trying to access a page with restricted access.

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.

Excluding pages from the navigation with the Nav Menu Role plugin
Excluding pages from the navigation with the Nav Menu Role plugin

The following allows you to compare how the menu will appear on the front-end for VIP members and visitors.

Menu that VIP members will see - it includes the VIP dashboard page
Menu that VIP members will see – it includes the VIP dashboard page

Menu that visitors will see - the VIP dashboard is not showing
Menu that visitors will see – the VIP dashboard is not showing

In summary

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.

Questions?

If you have any questions please not hesitate to post them on the Memebership Sites support page