Skip to main content

Managing Content Access with AAM Shortcode

Vasyl MartyniukRestricted ContentAbout 2 min

Controlling access to specific sections of content within posts or pages can be a crucial aspect of managing a website. Advanced Access Manager (AAM) provides a powerful solution through its shortcode [aam context="content"], allowing users to selectively hide, limit, or show content based on various criteria. In this article, we will explore the capabilities of AAM shortcodes and how they can be effectively implemented to tailor content visibility to specific user roles, capabilities, or user IDs.

Understanding AAM Shortcode

AAM shortcode [aam context="content"] comes with four attributes that can be customized to achieve the desired content access control:

  • hide. This attribute is used to specify comma-separated list of roles, capabilities, user IDs, or reserved words (e.g., "visitor," "authenticated," or "all") to hide the content from.

  • show. Allows you to define list of roles, capabilities, user IDs, or reserved words to explicitly show the content for.

  • limit. Similar to "hide" and "show," this attribute restricts content access based on specified roles, capabilities, user IDs, or reserved words.

  • message. If the "limit" attribute is defined, this attribute contains a teaser message instead of the restricted content.

Examples of Usage

To illustrate how AAM shortcodes work, let's hide content from users with the role "Editor" and specific user IDs (5 and 7):

[aam context="content" hide="editor,5,7"]

In the next example, we display a teaser message for users without the "edit_pages" capability:

[aam context="content" limit="all" show="edit_pages" message="You need to have the ability to edit pages to see this content"]

Using Reserved Keywords

AAM shortcodes also support reserved keywords like "visitor," "authenticated," or "all" to simplify access control for different use cases.

  • visitor. Represents anybody who is not authenticated.
  • authenticated. Describes anybody who is authenticated.
  • all. Encompasses everybody, regardless of authentication status.

In this example, we will hide content from everybody except those who are authenticated:

[aam context="content" hide="all" show="authenticated"]

Evaluation Order of Shortcode Attributes

AAM evaluates the shortcode attributes in the following order:

  • If the "hide" attribute is defined and the current user matches the specified criteria, the content will be hidden.
  • If the "limit" attribute is defined and the current user matches the specified criteria, the content will be limited.
  • If the "show" attribute is defined and the current user matches the specified criteria, the content will be shown despite "hide" or "limit" attributes.

Conclusion

Incorporating AAM shortcodes into your WordPress site empowers you to finely control content access based on user roles, capabilities, or specific user IDs. By understanding and implementing these shortcodes effectively, you can create a personalized and secure user experience. If you have any questions or need further clarification, feel free to reach out.

Virtual Assistant