Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: Conditional Exclusion of a xProfile Fields Group from editing

@danbp

Participant

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' );
Skip to toolbar