Content Sections

With Groups, you can protect parts of your posts, pages and content from other post types. Instead of protecting an entry completely, you could show only parts of it. This makes the entry still visible to anyone but hides certain parts from normal visitors, users who don’t belong to the right group. In addition, you can also hide content from group members. Besides protecting parts of your content based on groups, you can also use capabilities to decide whether a section should be shown or not.

So, how is this done? You can edit your entries as usual – Groups allows you to limit the visibility of as many content sections as you like by simply enclosing them within shortcodes.

The shortcodes that are involved are [groups_member], [groups_non_member], [groups_can] and [groups_can_not].

Let’s have a look at a simple example:

Here's some unprotected content.
Anyone can see this.

[groups_member group="Registered"]
But this section is different, only registered users will see this.

Here's some more content which anyone can see.

[groups_member group="Premium"]
And this section is shown only to users in the Premium group.

Please copy the above and past it on page. Now visit the page while logged out (you can simply use another browser than the usual one) and you will see the content is limited. Now log in as a normal user or if you have created the Premium group, log in with an account that belongs to it. In both cases, you will see more based on the account’s membership.

This is what our editor shows after pasting the example on a new page:

Editing a new post with protected content sections.

For someone who is not logged in, this is what the visitor will see:

The page content viewed by a normal visitor.

The content section that is protected and only shown to registered users who are logged in will show more. A registered user will see the protected content section:

And a member of the Premium group will see everything:

You can use as many instances of the shortcodes used to protect content sections on the same page and on as many entries you want.

You can also nest shortcodes as long as they are different. You can’t nest two instances of the same shortcode because the way these are interpreted by WordPress is limited. This is true for any shortcode, not just those provided by Groups. Anyhow, here’s an extended example with different shortcodes, including a nested section:

[groups_non_member group="Registered"][groups_login][/groups_non_member]
[groups_member group="Registered"]
You are connected!
[groups_non_member group="Premium"]
Why don't you join the Premium group?
[groups_join group="Premium"]
[groups_can capability="manage_options"]You've got the power![/groups_can]

This is how it looks like in our editor:

An extended example with different nested shortcodes.

That’s how the page will appear to a simple visitor:

The extended example as seen by a visitor.

And here is what a registered user sees:

A registered user viewing the page with the extended example. Not a member of the Premium group.

What a Premium member sees who also has the manage_options capability:

A Premium group member who also has the manage_options capability.