Problem:
Public visitors could still view single “event” (and similar) posts even when the post author no longer had the required membership role. An initial attempt using a
user_has_cap
filter to block
read_post
didn’t work reliably with the site’s setup (YOOtheme + memberships changing roles between “Professional Member” and “Customer”).
Solution:
Moved the restriction logic to the front-end request flow using
template_redirect
. On single posts of the target CPTs (e.g.,
event
,
profile
), the code fetches the post author, checks if they hold the
professional_member
role, and—if not—forces a 404 response. This bypasses theme/layout nuances and consistently hides content by author role. The same pattern can be extended to additional CPTs (e.g.,
facilitator-profile
) and/or different role slugs.
Relevant Documentation:
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
This topic contains 5 replies, has 1 voice.
Last updated by 20 hours, 33 minutes ago.
Assisted by: Christopher Amirian.