@henrywright, Thanks for this.
So that totally gets me where I need to be, checking for connections status. Any clue where I would apply that logic to hide the Profile navbar? I’m sure I can do it with some CSS trickery, but was wondering where that nav is initiated.
Hi @dmccuiston,
here is another solution which let you remove easily nav and subnav items to any visitor and users who are not friends.
If one or all items are removed, a message is displayed.
Put these 3 functions in bp-custom.php or child-theme functions.php
function bpfr_view_profile_msg() {
// msg in case the nav item is removed
if ( bpfr_maybe_hide_friends_nav_etc( $retval ) )
echo'<h3>Sorry, you can only view the profile of your friends !</h3>';
}
add_action( 'template_notices','bpfr_view_profile_msg' );
function bpfr_maybe_hide_friends_nav_etc() {
$retval = false;
// condition
if ( bp_is_user() && ! bp_is_my_profile() && ! friends_check_friendship( bp_displayed_user_id(), bp_loggedin_user_id() ) ) {
$retval = true;
}
return $retval;
}
function bpfr_hide_friends_nav_to_non_friends() {
// stop if condition is not ok
if ( ! bpfr_maybe_hide_friends_nav_etc() ) {
return;
}
// otherwise we remove the nav items
// bp topnav items
bp_core_remove_nav_item( 'profile' );
bp_core_remove_nav_item( 'groups' );
bp_core_remove_nav_item( 'forums' );
//bp subnav items
bp_core_remove_subnav_item( 'activity', 'friends' );
bp_core_remove_subnav_item( 'activity', 'mentions' );
}
add_action( 'bp_ready', 'bpfr_hide_friends_nav_to_non_friends' );
@danbp,
Thanks for this. I am going to drop this in and let you know what happens. Truly appreciated!