Skip to:
Content
Pages
Categories
Search
Top
Bottom

How add filter to bp_the_profile_group_field_ids?


  • SimpleOne
    Participant

    @simpleone

    I’m a total novice with PHP and need some help with creating some code to go inside my functions.php file. The code I need is a clone of the call to bp_the_profile_group_field_ids() that will filter out 3 xprofile field names that I don’t want users to be able to edit.

    Background: I’ve successfully modified the edit.php file to not display those 3 “required” fields (because I don’t want users to be able to edit them). However, the problem I discovered is that after modifying the edit.php file to hide those 3 fields (which I make “required” during registration), when a user clicks “Save Changes” on their Edit Profile page, it results in the message: “Please make sure you fill in all required fields in this profile field group before saving” (even though all required fields have data in them).

    Through my online research, I found that the following line of code in the edit.php file is the problem…

    <input type="hidden" name="field_ids" id="field_ids" value="<?php bp_the_profile_group_field_ids() ?>" />

    Apparently, the call to bp_the_profile_group_field_ids() which creates a list of the expected field names does not have a filter. So I would need to clone that function in my functions.php file and manually filter out my 3 desired fields from the string that gets generated.

    Anyone able to help with this… PLEASE?

Viewing 10 replies - 1 through 10 (of 10 total)

  • danbp
    Moderator

    @danbp

    Hi @SimpleOne,

    read from line 154 in bp-xprofile-classes.php file. It contains many information for what you want to do.
    See also on Codex here and here

    You can also revert your changes back and use this kind of function (goes into theme’s functions.php or bp-custom.php):

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

    May this help ? 😉


    danbp
    Moderator

    @danbp

    In addition, i woud warn any user who want to use bp_parse_args to exclude profile groups (exclude_groups only), that you will get a php warning.
    To avoid this, please read this ticket and apply the patch (BP 1.5 to 2.0.1).


    SimpleOne
    Participant

    @simpleone

    @danbp,

    Thanks. I tried inserting your suggested code into my functions.php, but it did not hide the desire fields. Also, I looked at the references in the links you provided for me to read through. Thanks for those too. However, I’m still stuck on how to resolve my problem.

    Just to be clear… I think what I specifically need to figure out is how to add a filter to bp_the_profile_group_field_ids(), which apparently creates a list of the expected field names (for the specific group tab that I’m currently on) when I click “Save Changes” button on Profile Edit page. Until I can find a way to filter out my 3 desired “required” fields during the Save Changes button press, I will continue to receive the error message: “Please make sure you fill in all required fields in this profile field group before saving“.

    Is there some other type of coding I can try to insert inside functions.php to resolve this?


    shanebp
    Moderator

    @shanebp

    danbp’s function works fine here.
    Although in BP 2.0+, bp_is_profile_edit() should be bp_is_user_profile_edit() to avoid the deprecation notice.

    Are you sure you’re inserting the correct ids?

    Try this and see if it hides the Name field:

    $retval['exclude_fields'] = '1';


    SimpleOne
    Participant

    @simpleone

    @shanebp,

    OK, so this is interesting. When I tried inserting the code from @danbp in the functions.php file for another test site that I have, it worked! All 3 fields were successfully hidden during Profile Edit, and I no longer received the error message that all required fields must be filled in. Yippee!!!

    Still not sure why I cannot get this to work on my first site, though. FYI, I’m running BP 1.9.1 on that one, and on the other test site (where I got this to work), I’m running BP 2.0.1. I even tried removing all code from my functions.php file on my first site and just leaving the above code, but that didn’t make any difference. So I’m still scratching my head trying to understand why this would work on one of my sites, but not the other.

    NOTE: I did discover that this solution ONLY works if you do not have a required field set up in your base profile group. Otherwise, you will still receive the error message about needing to fill in required fields when you click the Save Changes button. I found a way to get around this by moving all required fields (like Display Username) out of the base profile group and putting those required fields in a different profile group.


    danbp
    Moderator

    @danbp

    @simpleone,
    you found the reason why it doesn’t work on one site and not on the other !
    1.9.1 and 2.0.1 are sligthly different BP version !
    And the function you mention whas only introduced in BP 2.0, so this can’t anyway work on previous versions.

    Actually there is a small bug in BP 2.0+ when using this function to modify profile groups. I opened a ticket about this and @imath provided a patch that works and let the function handle correctly on profile groups. I personnally use this function to conditionnally show/hide fields from the base group without problems. My profile form contains over 20 fields in differents groups, even Base, and are all required and viewable by members only.

    I advise you to cancel whatever you have done about this so far, to apply the patch, to add the function to bp-custom.php and to test again.


    SimpleOne
    Participant

    @simpleone

    @danbp,

    I appreciate your advice and suggestions. I’ve got things working the way I want now.


    Iurie Malai
    Participant

    @flegmatiq

    @simpleone,

    Can you show how you solved your problem? danbp‘s code did not work for me. As you, I also wanted to hide some xprofile fields and tabs that I don’t want users to be able to edit.


    SimpleOne
    Participant

    @simpleone

    @flegmatiq, you can find my solution in this thread.


    Iurie Malai
    Participant

    @flegmatiq

    @SimpleOne, thank you, I will test that!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘How add filter to bp_the_profile_group_field_ids?’ is closed to new replies.
Skip to toolbar