Skip to:
Content
Pages
Categories
Search
Top
Bottom

How hide an xprofile field group on profile edit page?


  • SimpleOne
    Participant

    @simpleone

    I am using 6 xprofile field groups. But I want the Group 6 tab to be hidden from users when they go to edit their profile.

    How do I remove that Group 6 tab so that it doesn’t appear on the user’s profile edit page?

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

  • SimpleOne
    Participant

    @simpleone

    Anyone?


    danbp
    Moderator

    @danbp

    Hi @simpleone,

    you can actually only hide xprofile fields. Hiding field groups is not possible, due to a bug.
    But it is corrected for 2.1 and you’ll find a patch on the trac.

    You can already apply the patch to 2.0.2 bp-xprofile-classes.php and the above snippet will work. Add it to bp-custom.php or theme’s functions.php

    To hide an xprofile group, use bp_parse_args like this:

    function bpfr_make_profile_tab_members_only( $retval ) {
    	// hide to non members
    	if( !is_user_logged_in() ) {
               // exlude groups, separated by comma
    		$retval['exclude_groups'] = '4,5';
               // exclude fields, separated by comma
           		$retval['exclude_fields'] = '1,39';			
    	} 
    	return $retval;	
    }
    add_filter( 'bp_after_has_profile_parse_args', 'bpfr_make_profile_tab_members_only' );

    SimpleOne
    Participant

    @simpleone

    @danbp thank you very much for that helpful information! However, I’ve never applied a patch before. I’m not sure what to do with the patch once I download the file.

    Would you be kind enough to provide me with some guidance on installing a patch?


    danbp
    Moderator

    @danbp

    How to work with versionned file from SVN is too long to explain in a forum topic. Google around this subject or see on WP codex. But it is not necessary to learn that for just this modification.
    In your (this) case, it is very simple to do in fact.

    As you can see, the patch contains code, highlighted in red and green in regards of the line numbers he belongs to.

    The red code is the actual code (the one who should be modified)
    and the green code is the new one who replace the red line.

    To do it correctly, you check the line number on the patch and read attentively the code. Not for learning it, but to have a visual memory of it. 😉

    You do the same in your file, with help of a text editor like notepad+ which shows your file line numbers.
    You erase the red part and you copy/paste the green part at the same place.

    When finished, your file must only contain the green part. Or to avoid any error, you can comment the old code and add the new code, so you could revert back if needed. Or you can also made a copy and put it in a safe place before modifying the original file.

    A patch also contains code who isn’t highlighted before and after the modified lines. So you can easyly check what you do and where all this happens.

    Hope to be clear.


    SimpleOne
    Participant

    @simpleone

    @danbp thank you for the guidance on how to utilize a patch! Unfortunately, after I applied the changes (I believe correctly) to bp-xprofile-classes.php and also included your snippet inside my functions.php (and referencing the desired group number to be hidden), I was not successful in hiding the specific group that I want hidden.

    How soon do you expect that BP 2.1 will be coming out? (Perhaps if it’s coming out hopefully soon, I could just wait for that BP 2.1 version instead of continuing to try and figure out how to get the patch to work.)


    danbp
    Moderator

    @danbp

    I tested the snippet and applied the patch to 2.0.2 and it works. So i guess you did something wrong. 🙁

    BP 2.1 is expected in 12 days !


    SimpleOne
    Participant

    @simpleone

    @danbp OK, very good to know that BP 2.1 is 12 days away. Perhaps I will just wait until then and apply the upgrade and subsequently add your snippet to my functions.php.

    And yeah, I must have done something wrong when trying to manually apply the patch to bp-xprofile-classes.php. Thanks again for your help and guidance.


    danbp
    Moderator

    @danbp

    Just realized that you wanted to hide xprofile groups on the profile edit page !

    Add bp_is_profile_edit() to the if

    if( is_user_logged_in() && bp_is_profile_edit() )


    SimpleOne
    Participant

    @simpleone

    @danbp unfortunately adding that additional conditional didn’t make any difference. Perhaps it could be some small parameter that I missed when manually modifying the code in the file. I’ll try again later to redo it when I’m not so tired.

    On a separate note, I did notice that in the patch there is a reference to bp-xprofile-group.php. However, that’s a file that doesn’t appear to currently exist (at least not when I searched the BP 2.0.2 files installed on my server). I concluded (perhaps incorrectly?) that the patch developer kept that in there as a reference for the test case that was done to verify this patch works? Or am I perhaps suppose to add a new file with the name bp-xprofile-group.php and include the code that follows that section in the patch?

    Here’s the part I’m referring to…

    diff --git tests/phpunit/testcases/xprofile/class-bp-xprofile-group.php tests/phpunit/testcases/xprofile/class-bp-xprofile-group.php
    index 46f548f..699911b 100644
    --- tests/phpunit/testcases/xprofile/class-bp-xprofile-group.php
    +++ tests/phpunit/testcases/xprofile/class-bp-xprofile-group.php
    @@ -67,4 +67,37 @@ class BP_Tests_BP_XProfile_Group extends BP_UnitTestCase {

    danbp
    Moderator

    @danbp

    FYI:
    The original file is in buddypress/bp-xprofile/bp-xprofile-classes.php (BP 2.0.2)
    The patched code is here.
    The part you mention is for developpers unit test. You have nothing to do with that. 😉

    Here you can download a copy of the patched file I use. You put it here:
    wp-content/plugins/buddypress/bp-xprofile/
    And here the code to add into bp-custom.php

    function bpfr_hide_profile_field_group( $retval ) {
    	// hide profile group to members when on profile edit
    	if( is_user_logged_in() && bp_is_profile_edit() ) {
               // exlude groups, separated by comma
    		$retval['exclude_groups'] = '6';          		
    	} 
    	return $retval;	
    }
    add_filter( 'bp_after_has_profile_parse_args', 'bpfr_hide_profile_field_group' );

    SimpleOne
    Participant

    @simpleone

    @danbp I appreciate you taking the time to provide me with the specific changes and also to point me to the exact file to download. I did exactly as you described above…

    1. Placed your copy of the patched file in my bp-xprofile directory.
    2. Copy/pasted your code snippet into my theme’s functions.php (since I don’t already have a bp-custom.php already created).

    But yet the chosen group id was not hidden upon going to Profile Edit page. I just don’t understand why this isn’t working for me! I even tried including multiple group id’s to hide in the filter to see if that would make a difference, but those weren’t hidden either.

    Would it matter that I have my group_order (i.e., the order in which my field groups are displayed) arranged in a specific order?


    danbp
    Moderator

    @danbp

    Would it matter that I have my group_order (i.e., the order in which my field groups are displayed) arranged in a specific order?

    No !
    Anyway, i was wrong myself. Apologize. My snippet hides groups from viewing, not from editing. But you can get another trick on this post. And this one works realy. 😉

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘How hide an xprofile field group on profile edit page?’ is closed to new replies.
Skip to toolbar