function bb_same_profile_type_contact_allowed() {
if ( ! is_user_logged_in() || ! function_exists( 'bp_is_user' ) || ! bp_is_user() ) {
return;
}
$current_user_id = get_current_user_id();
$displayed_user_id = bp_displayed_user_id();
if ( ! function_exists( 'bpxcftr_get_field_id' ) ) {
return;
}
$profile_type_field_id = bpxcftr_get_field_id( 'Profile_Type' ); // Replace 'Profile_Type' with the name of your profile type field
if ( ! $profile_type_field_id ) {
return;
}
$current_user_profile_type = xprofile_get_field_data( $profile_type_field_id, $current_user_id );
$displayed_user_profile_type = xprofile_get_field_data( $profile_type_field_id, $displayed_user_id );
if ( $current_user_profile_type !== $displayed_user_profile_type ) {
// Remove the ability to send a private message.
remove_action( 'bp_member_header_actions', 'bp_send_private_message_button' );
// Remove the ability to send a friend request.
remove_action( 'bp_member_header_actions', 'bp_add_friend_button' );
}
}
add_action( 'bp_before_member_header', 'bb_same_profile_type_contact_allowed' );