Determine if a user is on the Members list:
if( bp_current_component('members') )
Determine if a user is on a profile page:
if ( bp_is_user() )
Thanks, Shane!
So, I would have to check, if a user is on the Members list/a profile page. Done with your code. But I would have to check, if he is a “subscriber”, too – and in this case redirect him to another url. Any hints, how to achieve that and where to place the code?
Here is a solution to exclude users, that are not logged in: https://buddypress.org/support/topic/hide-profile-from-non-logged-in-users/#post-147745.
But how to exclude/redirect users, that have the user role “subscriber”? Redirect might be working with
<?php wp_redirect( home_url() ); exit; ?
‘subscriber’ is a WP role.
Google ‘wp is user subscriber’
Current user id: bp_loggedin_user_id()
Okay, seems like I really have to learn more about PHP. Via google I found https://wordpress.stackexchange.com/questions/60272/find-out-if-logged-in-user-is-not-subscriber. That gave me a rough idea, but I did not manage to change the code for a redirect.
However, I found a workaround. I placed the following code…
<?php if ( current_user_can('member') ) : ?>
and
<?php endif; ?>
in these files:
/wp-content/plugins/buddypress/bp-templates/bp-legacy/buddypress/members/index.php (lines 27 and 144)
/wp-content/plugins/buddypress/bp-templates/bp-legacy/buddypress/members/single/home.php (13 and 122)
There´s no redirection now, but the content is not visible anymore for the role “subscriber”, but visible for “member”.