Show/Hide protected content based on user roles
-
On my page I have some content which is only visible for certain user roles.
I show the protected content to the user roles (‘member’ and ‘premium-members’) like this:$user = wp_get_current_user(); $allowed_all = array( 'member', 'board' ); $allowed_pemium_only = array( 'premium-members' ); if ( array_intersect( $allowed_all, $user->roles ) ) { echo 'Only visible to members and premium-members'; } if ( in_array( 'premium-member', $user->roles[0] ) ) { echo 'Only visible to premium members'; }
When I search for a certain protected content (for example content that is only visible for premium-members), the content itself does not show up but the pages on which the particular content is found do even if I’m just a member or not logged in at all. So this indicates that on these particular pages the content I searched for could be found but is hidden.
So my question is: Is there a filter or anything that can be used to strip out the search results that are hidden to certain user roles?
Many thanks in advance for any help.
- The topic ‘Show/Hide protected content based on user roles’ is closed to new replies.