The status shortcodes can be used to display content to users based on their login status. There are two shortcodes:
Logged in content
The logged in shortcode is used for content that will display to a user that is logged in. This can be used on any page, including special pages created with other shortcodes, such as the user profile area or a registration page.
Basic usage of the shortcode:
[wpmem_logged_in] This content can only be seen by logged in users. [/wpmem_logged_in]
Beyond the basic usage, the shortcode accepts the following attributes:
- Meta Key/Meta Value
ID and Role attributes
The logged in shortcode can be used to display content only to specific user IDs or to specific roles.
The following example will display content only to a user whose ID is 123:
[wpmem_logged_in id=123]This content will only display to the user whose ID is 123[/wpmem_logged_in]
The following example will display content only to a user with the editor role:
[wpmem_logged_in role=editor]This content will only display to users with the editor role[/wpmem_logged_in]
Multiple IDs or roles can be specified when separated by commas.
This example would display only if the user has an ID of 123, 345, or 456:
[wpmem_logged_in id="123,345,456"]This appears to users with ID 123, 345, or 456[/wpmem_logged_in]
This would only display if the user has a role of “editor” OR “subscriber”:
[wpmem_logged_in role="editor,subscriber"]This content displays for editor role and subscriber role[/wpmem_logged_in]
Meta Key and Meta Value attributes
The logged in shortcode can also be used to display content to users who have a specific meta key/value. The attributes should be used as a pair as passing the key to check and the value is currently required.
For example, this would restrict content to users who have “the_value” as the value of “my_special_field”:
[wpmem_logged_in meta_key="my_special_field" meta_value="the_value"]This is restricted to users who have “the_value” as the value for “my_special_field”[/wpmem_logged_in]
For restricting content to user who have a specific membership product enabled, you can specify the product slug using the “product” attribute:
[wpmem_logged_in product="my_membersip_product_slug"]This will display to users who have “my_membership_product_slug” access.[/wpmem_logged_in]
Subscription content (PayPal extension only)
When used with the premium add-on module WP-Members PayPal Subscription extension it should first be noted that the basic logged in/out parameters are unaffected. For example, if content is wrapped with the status shortcode for logged in status, the content will be viewable to a logged in user regardless of whether their subscription has expired or not. The reason for this behavior is that some content may be necessary for a user to see when they are logged in, even if they are expired.
For subscription content that should be shown only if a user is logged in AND has a current (paid) subscription, the status shortcode will accept the “sub” attribute (for “subscription” or “subscribers only”). This attribute can also accept a second optional parameter of “msg” to display a message that the content is based on subscription and the user is expired. The “msg” attribute is a true/false boolean and defaults to false if not set. A value of true will display the message, false will not.
[wpmem_logged_in status="sub" msg="true"]This is content for current subscribers only. If the “msg” parameter is false or omitted, it will simply not display. If “msg” is true, an expiration message will display in place of the protected content[/wpmem_logged_in]
Logged out content
The logged out shortcode displays content that will be shown to a user that is not logged in. This can be used on any page, including special pages created with other shortcodes, such as the members settings area or a registration page.
[wpmem_logged_out] this content displays when a user is not logged in. [/wpmem_logged_out]