[memb_has_membership]

Version Added v2.44.52

Summary

Conditional shortcode to control access to portions of a post, page or widget based on the logged in user’s membership level.

Shortcode Examples

[memb_has_membership membership="gold"]
   Shown to users with the gold membership level
[else_memb_has_membership]
   Shown if user doesn’t have the gold membership level
[/memb_has_membership]

If you’d like to restrict access to allow more than one group to see content, while restricting others who don’t have those memberships, you can do so by separating each membership name with a comma.

[memb_has_membership membership="gold,silver"]
   Shown to users with either gold or silver or both
[else_memb_has_membership]
   Shown if user doesn’t have specified tags
[/memb_has_membership]

Shortcode Parameters

capture:  Capture the output of the shortcode and route it to a variable for later use. (?)

memberships: A comma separated list of membership names to check for.

not:  You can use the attribute not=”not”, to reverse the results of the test.

output: Content to be displayed if the test is successful. (Optional, Added in 2.45)

txtfmt: A comma separated list of text processing functions to be used to post process the contact fields. (?)

Description

One of the core functions of Memberium is to control access to the pages on your WordPress website based on the identity of the logged in member. This is useful when you want to prevent access to content, or to dynamically control what content is displayed to visitors based on the membership levels that they have. A member can have zero, one, or multiple membership levels active, depending on what tags they have.

Why Membership Levels and not Tags

Membership levels are composed of sets of tags which can grant or block access. Using a tag check to check for the membership level is less reliable, because a contact may have a membership tag that is blocked by a PAYF, CANC or SUSP tag. This function checks your access against the active membership levels for that contact.

Conditional Memberships

[memb_has_membership] is a conditional shortcode. Conditional shortcodes perform a test and then display (or don’t display) the content within the shortcode depending on the result of the test. Conditional shortcodes are often nestable so that you can perform multiple tests. All tests are binary meaning they resolve to a simple true-false / sucess-fail / yes-no condition.

Nesting

If you have a series of tests, one after another, you may need to nest your shortcodes.

Administrators

Administrator accounts are always treated as having all access levels active. It is not possible to get a failure result as an Administrator. It is recommended that you create regular subscriber users to test the behavior of the site.

Shortcode Attributes

Conditional: Yes (?)
Nestable: Yes (?)
Accepts formatting: Yes (?)
Capturable: Yes (?)

Additional Information

The [else_memb_has_membership] shortcode is entirely optional.  If you skip the [else clause, then the contents of the shortcode will only be displayed on success, and nothing will be displayed on failure.

For more complex conditions, you can nest conditional shortcodes within each other.

In order to keep things clear, as you nest your shortcodes, put a digit at the end of the shortcode name, so that the shortcode processor can tell which shortcode pieces go together.

For example:

For example:

[memb_has_membership1]
     [memb_has_membership2]
    [else_memb_has_membership2]
    [/memb_has_membership2]
[else_memb_has_membership1]
[/memb_has_membership1]

If the shortcodes end before the next one starts, you are not nesting them and do not need to number them:

[memb_has_membership]
[else_memb_has_membership1]
[/memb_has_membership]

[memb_has_membership]
[else_memb_has_membership]
[/memb_has_membership] 

If you are nesting different shortcodes, you do not need to number them:

[memb_has_membership]
     [memb_has_any_tag]
    [else_memb_has_any_tag]
    [/memb_has_any_tag]
[else_memb_has_membership]
[/memb_has_membership]