WordPress Restricted Site Access (SAR) - Shortcodes


Access Restriction Shortcodes

Back to User Guide

TIP: What Are Shortcodes

Shortcodes add dynamic content to your site via a small piece of code. Learn more: Shortcodes - How To Use

The WordPress Restricted Site Access 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. Note: since the version 1.5.7 the parameter userid can accept more than one value. Multiple user IDs must be separated by comma.
  • 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.
  • deniedtext_html - Text that you can edit using html in the special form. Will be displayed for the users that are not allowed to see the content. Note: this feature was introduced in version 1.5.4. Learn more about how to use this shortcode: WordPress Restricted Site Access (SAR) - How To - Customize the Message for Restricted Users With HTML
  • 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 logged-in users. Guest users will see the message defined in the special form:

    [access login="1" deniedtext_html] Here will be displayed text from special form[/access]

  4. Show content only to users that can moderate comments and switch themes.

    [access cap="moderate_comments"]  Put the restricted content here [/access]

  5. Show content only to the user with ID "111"

    [access userid="111"]  Put the restricted content here [/access]>

  6. DON'T show content to the user with ID "111".

    [access userid="111" reverse="1"]  Put the restricted content here [/access]

  7. 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]

  8. Show content only to users with ID "2", "12" and "158" (note: multiple user IDs are supported only since the version 1.5.7).

    [access userid="2,12,158"]


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.

User Dashboard

Note: this shortcode was introduced in version 1.7.5.

The plugin allows to create and display a user dashboard. To display a user dashboard, you need to place the following shortcode on the needed page:

[cmsar-dashboard]

The shortcode has a parameter view which allows to display a user dashboard in either Tabs or Accordion views.

Examples:

[cmsar-dashboard view="tabs"]

[cmsar-dashboard view="accordion"]

Learn more about the user dashboard in this guide:


More information about the WordPress Restricted Site Access 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
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.