/

Site Access Restriction (SAR) - Shortcodes


Access Restriction Shortcodes

Back to User Guide

The plugin uses a shortcode which supports restricting content only to part of the content within the post / page. This means that the entire post can be visible and only part of it will be visible to specific users.

Basic Shortcode

The basic shortcode looks like this:

[access] Put the restricted content here [/access]

The shortcode needs some extra information about who should have access to the content. 


Choosing Restrictions

To define who gets restricted, you can include parameters to the shortcode.  All parameters are optional. This is a list of the parameters with explanations. A series of examples will follow.

  • role - Only affects logged-in users. Remember to use only lowercase. Only accepts one value.
    By default, WordPress has the following roles (Learn more in the  WordPress codex). 
    • super-admin
    • administrator 
    • editor
    • author 
    • contributor 
    • subscriber 
  • cap - The capabilities the logged-in user has (for instance, to edit pages). Only accepts one value.
    Check the list of capabilities the  WordPress codex.
  • userid - Identify users by ID. Only accepts one value.
  • guests - use guests="1" to show content only for guests (non logged-in) users.
  • login - use login="1" to show content only for logged-in users.
  • deniedtext - Text which will see users that cannot see the content.
  • reverse - Use reverse="1" to reverse the conditions (check the examples below for more information). 

Examples

  1. Show content only to users with the role of editor.

    [access role="editor"]  Put the restricted content here [/access]
  2. Show content only to guests. Logged-in users will see the message "This is the guest area!"

    [access guests="1" deniedtext="This is the guest area!"]  Put the restricted content here [/access]
  3. Show content only to users that can moderate comments and switch themes.

    [access cap="moderate_comments"]  Put the restricted content here [/access]
  4. Show content only to the user with ID "111"

    [access userid="111"]  Put the restricted content here [/access]>
  5. DON'T show content to the user with ID "111".

    [access userid="111" reverse="1"]  Put the restricted content here [/access]
  6. DON'T show content to users that have a capability to upload files.

    [access cap="upload_files" reverse="1"] Put the restricted content here [/access]

Nesting

It's possible to use shortcodes inside the [access] shortcode. Doing so is called nesting.

For example:

Showing a route from Routes Manager only to administrators

  • [access role="administrators"]  [route-map id="111"] [/access]

Nesting The Access Shortcode

It's possible to nest [access] shortcodes for complex situations. That is, to insert conditions inside conditions.

Example:

Show content to users that have a capability to upload files, BUT don't show it to user with the id "111":

  • [access cap="upload_files"] [access userid="111" reverse="1"] Put the restricted content here [/access][/access]
Skipping Nested Shortcodes

The parameter doshortcode can be used when nesting to skip the process.

In the case below, all users with the capability to upload files will see the message "[access userid="111" reverse="1"]Put he restricted content here [/access]":

  • [access cap="upload_files" doshortcode=0]  [access userid="111" reverse="1"] Put the restricted content here [/access][/access]

Using this feature should be necessary only when dealing with extremely complex cases.


More information about the Site and Content Restriction WordPress Plugin

Other WordPress products can be found at CreativeMinds WordPress Store

Let us know how we can Improve this Product Documentation Page

To open a Support Ticket visit our support center