Skip to main content

[sso-if-content-requires]

Conditionally render a piece of a restriction message based on what the requested content requires — not on who is viewing it. This lets a single site-wide restriction message say different things depending on the role the gated content is limited to.

Use it when a logged-in visitor is denied access and you want the message to vary by the kind of content they hit — for example, a "become a member" note for general member content and an "upgrade to Prime" note for higher-tier content.

Content-side vs. user-side

[sso-if-content-requires] asks what the content requires. To branch on what the current visitor has (their roles or login status), use [protect-content] instead. The two can be combined in the same message.

Test the lowest tier, not the exclusive one

Content Gating lists every role allowed to view a page, so a page open to both Members and Prime Members has both roles in its list. Testing for the top tier (role="prime") is therefore almost always true and can't tell a Prime-exclusive page apart from a members-and-up page. Branch on the lowest tier that can access instead — test the base member role and use not="true" for the higher tier. See Which role should you test? for the full explanation.

Syntax

Use each role's slug (matching is case-sensitive — the slug, e.g. member, not the "Member" label):

[sso-if-content-requires role="member"]
This content is available to members. Your account doesn't include membership access.
[/sso-if-content-requires]

[sso-if-content-requires role="member" not="true"]
This content is exclusive to Prime members. Upgrade your membership to view it.
[/sso-if-content-requires]

Fields

AttributeTypeDefaultDescription
rolestring""One role slug, or a comma-separated list. The enclosed content renders if the requested content requires any of these roles (OR).
rolesstring""Alias for role. Values from both attributes are combined.
notstringfalseSet to "true" to invert the match — render when the content does not require the given role(s).

Notes:

  • Roles are matched against the post's Limit access to the following roles setting (the Content Protection metabox), so the slug you pass is the same role slug used for gating (e.g. prime, member).
  • Multiple roles are OR-matched: role="prime,gold" renders when the content requires either Prime or Gold.
  • With no role/roles attribute there is nothing to evaluate, so nothing is rendered.
  • On unrestricted content (no gating roles), a positive match renders nothing and a not="true" branch renders.
  • The evaluation is independent of the current visitor, so it is unaffected by login status or administrator privileges. (Because a restriction message only appears to denied visitors, and admins are never denied, the branch never surfaces to admins in practice.)

Where to use it

Place it inside any Content Protection message that is run through do_shortcode — most commonly the Site-wide restricted content message for users without sufficient permission field on the Yoko SSO & Content Protection settings screen. The restriction-message pipeline already processes shortcodes, so no extra configuration is needed.

  • [protect-content] — show or hide content based on the current user's roles or login status (operation="show|hide", role/roles, status="logged-in|logged-out"). Use this for user-side conditions.
  • Content Gating / Protection — the feature overview, including guidance on which tier to test and a worked example.

Hooks and Filters

yoko_sso_post_requires_role Filter

Overrides whether a given post is considered to require a role. Useful when access requirements are computed dynamically rather than stored only in the allowed-roles meta.

/**
* Treat everything under a membership taxonomy term as requiring Prime.
*
* @param bool $post_requires_role Whether the post requires the role.
* @param int $post_id The post being checked.
* @param string $role The role slug being checked for.
* @return bool
*/
function my_post_requires_role( $post_requires_role, $post_id, $role ) {
if ( 'prime' === $role && has_term( 'prime-eligible', 'membership', $post_id ) ) {
return true;
}
return $post_requires_role;
}
add_filter( 'yoko_sso_post_requires_role', 'my_post_requires_role', 10, 3 );