How to Restrict Content By Members in WordPress
Tags: wordpress, member, user
Published: 2021-05-08 08:49:35

Your WordPress website has some <strong>important</strong>, <strong>sensitive</strong>, or <strong>paid content</strong>, and you want to allow<strong> only a few users</strong> with a certain role to view them. Easy peasy! You can use a member plugin to <strong>restrict who is allowed to read content</strong> on your WordPress website.

<!--more-->

In this article, we're going to do it step by step with <strong>Restrict User Access</strong> plugin. But first, let's learn about the applications of restricting content by members in WordPress.

<h2>When Do You Need to Restricting Content by Members?</h2>

Restricting content by members can be applied for:

<ul>

   <li><strong>Online books websites</strong>: allow only VIP members to read paid books or hot books.</li>

   <li><strong>School websites</strong>: allow only teacher accounts to read private documents such as lesson plans and graduation theses.</li>

   <li><strong>Company websites</strong>: allow only manager accounts to read private documents or internal reports.</li>

   <li>And many other applications, depending on your creativity.</li>

</ul>

For better illustration, I'm going to make an example of a <strong>company website</strong>. Here what I do:

<h2>How to Allow Only Certain Users to Read Content</h2>

In this article, I classify all users on the WordPress website into two levels: <strong>Manager</strong> and <strong>Staff</strong>. Staff can only read normal posts, while managers can read both normal and private posts.

To do so, I use <a href="https://wordpress.org/plugins/restrict-user-access/">Restrict User Access</a> plugin.

<img src="https://i.imgur.com/S3Fep99.png" />

Restrict User Access plugin helps you <a href="https://gretathemes.com/creating-a-wordpress-membership-website/">create a membership website</a> where users get different levels. Depending on the level, users are allowed to use features or read posts with increasing importance / secret.

Restrict User Access plugin is free and available on wordpress.org, so you just need to <a href="https://gretathemes.com/install-wordpress-plugin/">install and activate the plugin</a> as usual:

<img class="aligncenter" src="https://i.imgur.com/QJ5EAaT.png" alt="install and activate Restrict User Access plugin" />

Upon activation, a new section User Access will show on the sidebar on the back end of your WordPress website:

<img class="aligncenter" src="https://i.imgur.com/cNFZFT5.png" alt="a new section User Access will show on the sidebar on the back end of your WordPress website" />

This time, follow these below steps to restrict content by members in WordPress:

<h3>Step 1: Create Levels and Grant Capabilities for Them</h3>

First, go to <strong>User Access</strong> &gt; <strong>Access Levels</strong> &gt; <strong>Add New</strong>:

<img class="aligncenter" src="https://i.imgur.com/0yLh7Dw.png" alt="Create a new level to restrict content" />

In the <strong>Add New</strong> interface, you can create access conditions, apply the level to users, grant capabilities for the level, and set up other options such as duration, hide the admin bar, etc.

<img class="aligncenter" src="https://i.imgur.com/Sc8bCAl.png" alt="the interface to add new access levels" />

Now, name the level, and then move to the <strong>Capabilities</strong> tab to grant capabilities for this level:

<img class="aligncenter" src="https://i.imgur.com/Akf0QrO.png" alt="grant capabilities for the level" />

As you can see on the image, the first column contains capabilities that can be granted to the currently selected level (Manager). To grant a capability to <strong>Manager</strong>, just click on the corresponding cell in the <strong>Permit</strong> column; otherwise, click the cell in the <strong>Deny</strong> column.

In this article, I only focus on the capability to read articles or pages. Therefore, I only permit the following capabilities:

<ul>

   <li><code>read</code>: read normal posts / pages</li>

   <li><code>read_private_posts</code></li>

   <li><code>read_private_pages</code></li>

</ul>

As for other capabilities, I choose <strong>Deny</strong>.

<img class="aligncenter" src="https://i.imgur.com/TdKlsN8.png" alt="deny other capabilities of the access level" />

Next, don't forget to click <strong>Create</strong>.

We've finished the first level <strong>Manager</strong>. As for the <strong>Staff</strong> level, I do the same. But in the <strong>Capabilities</strong> tab, I only permit <code>read</code>.

<img class="aligncenter" src="https://i.imgur.com/zQc9720.png" alt="restrict content by the access levels" />

These are two levels (<strong>Manager</strong> and <strong>Staff</strong>) that I've created:

<img class="aligncenter" src="https://i.imgur.com/xF7eXoK.png" alt="two level we've created with Restrict User Access plugin" />

However, these levels still haven't been applied to any user. To do so, move to step 2.

<h3>Step 2: Apply the Level to Users</h3>

There are two methods to apply the level to users:

<ul>

   <li><strong>Method 1</strong>: Choose users manually</li>

   <li><strong>Method 2</strong>: Synchronize with user roles</li>

</ul>

Here we go!

<h4>Method 1: Choose Users Manually</h4>

Method 1 is suitable for internal company websites that have a few members (&lt;20 people) because it's time-consuming to choose numerous members manually.

First, go to<strong> User Access</strong> &gt;<strong> Access Levels</strong> and choose the level you want to apply to users:

<img class="aligncenter" src="https://i.imgur.com/YOVKOQS.png" alt="hoose the level you want to apply to users" />

Next, move to the <strong>Members</strong> tab, in the <strong>Search for Users</strong> section, fill in the user names and click <strong>Save</strong>.

<img class="aligncenter" src="https://i.imgur.com/pL0kMvE.png" alt="fill in the user names in the Members tab" />

<h4>Method 2: Synchronize with User Roles</h4>

Method 2 is faster than method 1 because you can utilize available <a href="https://gretathemes.com/the-user-roles-in-wordpress/">user roles</a> on your WordPress website. However, make sure that managers and staff are assigned the right user roles.

Read more: <a href="https://gretathemes.com/configure-user-role-wordpress-using-plugin/">how to configure user roles in WordPress</a>.

To synchronize with user roles, you also choose the desired level and go to the <strong>Members</strong> tab.

In the Synchronized Role section, choose the role you want to synchronize. In this example, I created two user roles (<strong>Manager Users</strong> and <strong>Staff Users</strong>) before, so I just need to synchronize them with the corresponding levels.

<img class="aligncenter" src="https://i.imgur.com/IZY8oXL.png" alt="Synchronize the Restrict User Access plugin with User Roles" />

Ok, now I'll check if we do it right. My WordPress website has three private posts and some normal posts as follows:

<img class="aligncenter" src="https://i.imgur.com/0ZPPGd3.png" alt="Restrict private posts and normal posts on the WordPress website by members" />

First, I log in with a <strong>Staff</strong> account. As you can see, I can't see private posts. They don't even show up:

<img class="aligncenter" src="https://i.imgur.com/nsQ3RKZ.png" alt="Content are restricted for Staff members" />

Next, I log in with a <strong>Manager</strong> account. And tada, I can see private posts now:

<img class="aligncenter" src="https://i.imgur.com/YxjnJuI.png" alt="Content is not restricted for Manager members" />

Restrict User Access has another interesting feature that is creating access conditions. With this feature, you can set up so that users in a level can only <strong>read certain posts that you specified</strong>.

<h2>How to Create Access Conditions</h2>

First, choose the level that you want to create access conditions for. In this example, I choose the <strong>Staff</strong> level:

<img class="aligncenter" src="https://i.imgur.com/a82IVZY.png" alt="create access conditions for the Staff level" />

Next, go to the <strong>Access Conditions</strong> tab and click <strong>New condition group</strong>:

<img class="aligncenter" src="https://i.imgur.com/RpfImkr.png" alt="add a New condition group:" />

Now, you can see a lot of condition types. However, we just focus on the capability of reading posts, so let's choose <strong>Posts</strong> / <strong>Blog</strong>:

<img class="aligncenter" src="https://i.imgur.com/6z4qw5J.png" alt="Choose the capability of reading posts" />

After that, click the box next to the <strong>Posts</strong> / <strong>Blog</strong> section, and then select the posts that you allow your users to read. For example, I choose the following posts:

<img class="aligncenter" src="https://i.imgur.com/sXUwKOH.png" alt="select the posts that you allow your users to read." />

Finally, don't forget to click <strong>Save</strong>.

From now on, Staff users are only allowed to read content that I specified above. As for other posts, although they can still see the title and featured images on the archive page, they can't read the post content.

<img class="aligncenter" src="https://i.imgur.com/dm2qoIc.gif" alt="Staff members can't read restricted content on the WordPress website" />

<h2>Last Words</h2>

<strong>Restricting content by members in WordPress</strong> is very crucial for websites that have sensitive, important, or paid content. You should utilize this technique to <strong>protect your website content</strong>.

Do you know any other application of restricting content by members in WordPress? Share it with us in the comment section!

See ya!