How to Restrict Access to Content with Members

Posted OnJan 8, 2015     CategoryPlugins, Question & Answer     CommentsNo comment

In this section of the guide to the Members plugin, we will show you how to restrict access to a page/post by adding restrictions to the Content Permissions area of a post/page.

For this example, we will restrict access to the page Restricted Permissions and customize the Error Message.

Step 1) Login to the WordPress Dashboard.

Step 2) From the left-hand sidebar of the Dashboard navigate to Pages -> Add New.

km-members-access-01a

Step 3) Complete the fields as outlined below:

A. Page Title Enter a Page Title.
For this example, Restricted Access was entered.
B. Page Body Enter text for the body of the page.
For this example, a small paragraph was entered (see screenshot below).
C. Content Permissions Place checkmarks in the appropriate checkboxes for the Role(s) you want to restrict access to.

For this example, the Administrator and Editor will be the only Roles that can access this page.

D. Custom Error Message In this area, you can add Shortcodes. Below are examples of the available Shortcodes.

  1. [access] shortcode

    This shortcode is used for hiding content from particular roles and capabilities.

    Example:
    [access role=”administrator,editor”]Hide this content from everyone but administrators and editors.[/access]

  2. [is_user_logged_in] shortcode

    The [is_user_logged_in] shortcode should be used to check if a user is currently logged into the site. If not, the content will be hidden. This shortcode has no parameters.

    Example:
    [is_user_logged_in]This content is only shown to logged-in users.[/is_user_logged_in]

  3. [feed] shortcode

    If you have content you only want to show to subscribers of your feed, wrap it in this shortcode. This shortcode has no parameters.

    Example:
    [feed]This content will only be shown in feeds.[/feed]

For this example, 1. will be used.

The Custom Error Message entered here will override the Custom Error Message entered in Settings -> Members.

km-members-access-02a

If you have completed the fields as outlined above, the page should now look as follows:

km-members-access-03a

Step 4) Click the Publish button to complete this process.

Testing the Code

Step 5) From your site, navigate to the newly created page, Restricted Permissions. If you are logged in as an Administrator or Editor you should be able to view this page.

Step 6) Log out.

Step 7) Log in using the login credentials for the User, Brad Smith created in an earlier guide and assigned the Role of Quality Control.

Notice that Brad can not view the content of this page instead the Custom Error Message created above is displayed.

km-members-access-09a

The next step of the guide will focus on How to Extend Members with Functions.

 

Tags:

Leave a Reply

Your email address will not be published. Required fields are marked *

Send this to friend