Since BP 2.0, you can use bp_parse_args to customise template loops and on a much easier way as never before.
The example function below will hide profile groups with ID 1 and profile fields IDs 6, 18 & 39 on the public profile screen of each member and stay visible on the edit screen. Tested & approved 2.0.1
If you get some php warning while using this function, be aware that there is a bug in 2.0.1 bp-xprofile-classes.php (fixed. See ticket). Simply apply the lattest patch to get rid of this error.
function flegmatiq_profiles( $retval ) {
// conditionnals to set accordingly to your purpose
if( !is_user_logged_in() && !bp_is_profile_edit() ) {
$retval['exclude_groups'] = '2';
$retval['exclude_fields'] = '6,18,39';
}
return $retval;
}
add_filter( 'bp_after_has_profile_parse_args', 'flegmatiq_profiles' );
In your particular case, you have to play with the conditionnals
The example below is to give you an idea how to handle this. Not tested !
function flegmatiq_profiles( $retval ) {
$myfield = xprofile_get_field_data( 'Faculty', $user_id );
if( empty( $myfield ) )
return; // or echo
if( $myfield == "Faculty" )
if( bp_is_profile_edit() ) {
$retval['exclude_groups'] = '1,56';
$retval['exclude_fields'] = '6,18,39'; .
}
if $myfield == "field_name_2";
// do something other...
return $myfield;
add_filter( 'bp_after_has_profile_parse_args', 'flegmatiq_profiles' );
@danbp, thank you! I tested your solution (the last function), but no success. Is enough to put this in the bp-custom.php file?
I tried the next simple function to hide the extended fields group number 2 from editing for all members, but it not working.
function flegmatiq_profiles( $retval ) {
if( bp_is_profile_edit() ) {
$retval['exclude_groups'] = '2';
}
return $retval;
}
add_filter( 'bp_after_has_profile_parse_args', 'flegmatiq_profiles' );
I use this function and it works.
Perhaps try to modify the field view of group id 2,in the profile setting. View for members only and set them also so that members cannot change the view.
Have you also applied the patch given in the ticket ?
Sorry to drop in on your thread but I was hoping you all might be able to recommend a buddypress developer to me? Please let me know if you can. Thanks!, Joe
@danbp, I applied the patch but the function does not works. If I put your function in the bp-custom.php I have a clean white page (display) as a result.
Generally after adding some custom code and getting a blank page afterward is due to a PHP error. So before saying it’s not working (and it is), you have to check attentively what you did. A missing semi-colon, apostrophe, etc….
@danbp, I know how to check for errors, but this didn’t helped me too much :). I solved with the blank page, but no more. Your solution works for hiding some xProfile tabs from viewing, but not from editing them. Am I wrong? Sorry!
This is my tested function (as I said, it hiding only from viewing, not from editing):
function flegmatiq_profiles( $retval ) {
if ( is_user_logged_in() && !bp_is_profile_edit() ) {
$myfield = xprofile_get_field_data( 'User Type' );
if( $myfield == "Faculty" ) {
$retval['exclude_groups'] = '2';
//$retval['exclude_fields'] = '6,18,39';
}
}
return $retval;
}
add_filter( 'bp_after_has_profile_parse_args', 'flegmatiq_profiles' );
The next code works as I need, but I think it is not so elegant, and it not allow to use the group ID, only his order number, as ordered by admin:
function hide_profile_group_tabs_from_editing( $group_names ){
if ( is_user_logged_in() && bp_is_profile_edit() && xprofile_get_field_data( "User Type") != "Faculty" ) {
for ($x=0; $x<=sizeof($group_names); $x++) {
if ( $x != 3 ) echo $group_names[$x]; //3 is the order number (from 0) of the tab that I need to hide in the profile edit page. This is not the group ID.
}
} else {
return $group_names;
}
}
add_filter('xprofile_filter_profile_group_tabs', 'hide_profile_group_tabs_from_editing');