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.,