Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] How to hide more than one profile field?

  • @simpleone

    Participant

    I have two profile fields that I need to hide from being displayed. I was able to successfully hide a single field by modifying some code in the profile-loop.php file using guidance I found in an old thread here: http://buddypress.org/support/topic/hide-profile-field/

    But I’m very new to PHP and don’t know how to modify the code using an OR statement to include the second profile field I need hidden. (I am assuming an ‘or’ statement is what I should include to accomplish this.)

    The guidance in above-referenced thread states the following:

    Change this line:
    while ( bp_profile_fields() ) : bp_the_profile_field();

    to:
    while ( bp_profile_fields() ) : bp_the_profile_field(); if ( bp_get_the_profile_field_id() != 'ID # YOU WANT TO SKIP' ) :

    then change the corresponding endwhile; line to:
    endif; endwhile;

    Can someone please tell me what additional revisions I should make to those lines of code in order to hide two fields (instead of just one field)?

Viewing 11 replies - 1 through 11 (of 11 total)
  • @simpleone

    Participant

    Anyone?

    @shanebp

    Moderator

    Try:

    while ( bp_profile_fields() ) : bp_the_profile_field(); 
    if ( bp_get_the_profile_field_id() != 'ID # YOU WANT TO SKIP' && bp_get_the_profile_field_id() != 'ID # 2nd field YOU WANT TO SKIP' ) :

    @simpleone

    Participant

    @shanebp, that worked perfectly! Thank you very, VERY much!!!

    @simpleone

    Participant

    Oops… I just found a problem.

    The good news is that I was able to successfully hide certain profile fields from being displaying (by modifying profile.php). That part works great. Also, I was able to hide the same fields from being displayed when a user goes to edit their profile.

    However, the problem I just discovered is that if any of those fields that I’ve hidden (using the above code changes) are “required” fields, then when a user goes to the Edit Profile page, the following error message appears upon clicking the Save Changes button: “Please make sure you fill in all required fields in this profile field group before saving.”

    Even though I’m certain those hidden fields have values in them, that error message appears and there’s no way to save changes.

    Any solution to this?

    @simpleone

    Participant

    Correction to my last post. I meant to say…

    I was able to successfully hide certain profile fields from being displaying (by modifying profile-loop.php). And I was able to hide the same fields from being displayed when a user goes to edit their profile (by modifying edit.php).

    NOTE: Both files are located in: /bp-templates/bp-legacy/buddypress/members/single/

    I still need help figuring out how to avoid the above-mentioned “required fields” error message upon clicking the Save Changes button.

    @commoneasy

    Participant

    Hi SimpleOne, I’m working on the same problem here! I tried to hide some fields from the edit profile page . i tried <

    
    div class="clear"></div>
    
    		<?php while ( bp_profile_fields() ) : bp_the_profile_field(); if ( bp_get_the_profile_field_id() != '15' ) :?>
    
    			<div<?php bp_field_css_class( 'editfield' ); ?>>

    to hide profilefield 15 from the editing page, unfortunatly it doesnt work, can you maybe send me a duplicate of your edit.php file? you would help me big time 🙂

    @simpleone

    Participant

    @commoneasy

    I found another solution that was suggested by someone in a different thread I had opened. Instead of modifying the edit.php file, I simply put the following code inside my functions.php file in my child theme. (Or you could put it in bp-custom.php.)

    Please be warned that this solution didn’t work when I tried it on my site running BP 1.9.1. (Even though my desired fields were successfully hidden by this solution, I still received a “required fields” error message after clicking the Save button.)

    So, in order for this to work, you need to be running BP 2.0 +.

    The below profile field ids 1, 32, and 48 correspond to the three fields I needed to hide from editing.

    function simple_one_hide_some_profile_fields( $retval ) {	
    	if(  bp_is_profile_edit() ) {		
    		$retval['exclude_fields'] = '32,48,1';	//field ID's separated by comma
    	}	
    	
    	return $retval;
    }
    add_filter( 'bp_after_has_profile_parse_args', 'simple_one_hide_some_profile_fields' );

    Try inserting the following into your functions.php or bp-custom.php and see if it works. I modified my above code specifically to hide your profile field id 15.

    function commoneasy_hide_some_profile_fields( $retval ) {	
    	if(  bp_is_profile_edit() ) {		
    		$retval['exclude_fields'] = '15';	//multiple field ID's should be separated by comma
    	}	
    	
    	return $retval;
    }
    add_filter( 'bp_after_has_profile_parse_args', 'commoneasy_hide_some_profile_fields' );

    @commoneasy

    Participant

    Wow thanks a lot man!! This works perfect 😀 for the intrested people, i put the code from SimpleOne in this exact file: wwwroot/wp-content/plugins/buddypress/bp-templates/bp-legacy/buddypress-functions.php

    @simpleone

    Participant

    Great! Happy to help. 🙂

    @commoneasy

    Participant

    Hi there, i have an additional question… can this be used to hide profile groups from the edit profile group tab ? I tried;

    // commoneasy hide fields
    function commoneasy_hide_some_profile_fields( $retval ) {	
    	if(  bp_is_profile_edit() ) {		
    		$retval['exclude_fields'] = '15';	//multiple field ID's should be separated by comma
    		
    	}	
    	
    	return $retval;
    }
    add_filter( 'bp_after_has_profile_parse_args', 'commoneasy_hide_some_profile_fields' );
    
    // commoneasy hide groups
    function commoneasy_hide_some_profile_groups( $retval ) {	
    	if(  bp_is_profile_edit() ) {		
    		$retval['exclude_groups'] = '4';	//multiple field ID's should be separated by comma
    		
    	}	
    	
    	return $retval;
    }
    add_filter( 'bp_after_has_profile_parse_args', 'commoneasy_hide_some_profile_groups' );

    unfortunatly it didn’t work, i hope somebody can help!

    @danbp

    Participant

    Group exclusion doesn’t work on a single install for the moment (only on MS).
    More advice on this here:
    https://buddypress.trac.wordpress.org/ticket/5650

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘[Resolved] How to hide more than one profile field?’ is closed to new replies.
Skip to toolbar