Primary

[groups_can]

This shortcode is used to reveal content sections based on capabilities. The content section it encloses is shown to users who have the requested capability and hidden from those who don’t.

The capability attribute is required and is used to indicate one or more capabilities separated by comma.

Supported attributes:

  • capability is required and must indicate one or more capabilities separated by comma – if more than one capability is given, the enclosed content is shown to any user that has at least one of the capabilities

Example

This example shows how to protect a content section so it is shown only to users who have the manage_options capability.

[groups_can capability="manage_options"]
Users who can manage options can see this.
[/groups_can]

You can test this easily by placing the above on a page. Visit the page as a user who has the Administrator role and the enclosed text should be displayed. Visit the page as a normal user with the Subscriber role and the text would normally be hidden. These affirmations hold, unless the user with the Subscriber role belongs to a group that grants the manage_options capability, or the Administrator role has had the capability removed.