Skip to:
Content
Pages
Categories
Search
Top
Bottom

Search Results for 'xprofile conditionnal fields'

Viewing 6 results - 1 through 6 (of 6 total)
  • Author
    Search Results
  • #234120

    In reply to: Noob recommendations

    danbp
    Moderator

    I published some BuddyPress use case, see here: http://bp-fr.net/realisations/
    There is also a category called showcase with some other examples.
    This will hopefully help you to see how BP is and can be used.

    – separating users is now possible with member_type (see codex)
    – scheduling is not avaible in BP, but thought there are some plugins for this (search on WP repo)
    – conditionnal xprofile fields is a popular question on the forum. You’ll probably find some discussion here.

    BuddyPress is first of all a great and awesome tool for building communities around the members.

    #230718
    danbp
    Moderator

    Hi @amic58, @tecca

    When BP is installed and xProfile is activated, the original WP profile settings are not accessible to user.

    The WP register process use only username, password and email and BuddyPress add by default a Name field as base for other extended profile fields.

    In short this means that username and name fields can contain a same information(a name, a pseudonym, a first or/and a last name). The plugin you mention is best for a WP install where user had choosen first/last name as output on post, comments, etc Once BP is activated, this became a little different.

    Now to the initial question.
    The CSS trick is a very inelegant solution as it lets everybody knowing how BP works to surround this invisibility. You’re also loosing any flexibility if you want to show some fields privately for example.

    You can do this properly with a little snippet, as explained here:

    Using bp_parse_args() to filter BuddyPress template loops

    Here’s an example which let you hide fields or fiels group to members, but not to site admin

    function bpfr_hide_profile_field_group( $retval ) {
    	if ( bp_is_active( 'xprofile' ) ) :	
    	
    	// hide profile group/field to all except admin	
    	if ( !is_super_admin() ) {		
    		//exlude fields, separated by comma
    		$retval['exclude_fields'] = '1';  
    		//exlude groups, separated by comma
    		$retval['exclude_groups'] = '1'; 			
    	} 
    	return $retval;		
    	
    	endif;
    }
    add_filter( 'bp_after_has_profile_parse_args', 'bpfr_hide_profile_field_group' );

    Add it to bp-custom.php or your child-theme functions.php

    Of course you can also choose to show a field or group, but remove the possibility for the user to edit it later. Simply add more conditionnal to the function.

    Here another example:

    function bpfr_hide_profile_edit( $retval ) {	
    	// remove field from edit tab
    	if(  bp_is_user_profile_edit() ) {		
    		$retval['exclude_fields'] = '54'; // ID's separated by comma
    	}	
    	// allow field on register page
    	if ( bp_is_register_page() ) {
    		$retval['include_fields'] = '54'; // ID's separated by comma
    		}		
    	
    	// hide the field on profile view tab
    	if ( $data = bp_get_profile_field_data( 'field=54' ) ) : 
    		$retval['exclude_fields'] = '54'; // ID's separated by comma	
    	endif;	
    	
    	return $retval;	
    }
    add_filter( 'bp_after_has_profile_parse_args', 'bpfr_hide_profile_edit' );

    Hope to be clear.

    #188236
    danbp
    Moderator
    #187770
    danbp
    Moderator

    Hi @mmadden,

    not sure i understand what you want to achieve. Are you creating a register page from scratch ?
    Anyway….
    Open the original BP register file (/buddypress/bp-templates/bp-legacy/buddypress/members/register.php). It contains many placeholders and conditionnals

    So, for the mandatory NAME xprofile group (the only one you use), you have line 65

    if ( bp_is_active( 'xprofile' ) ) : if ( bp_has_profile( array( 'profile_group_id' => 1, 'fetch_field_data' => false ) ) ) : while ( bp_profile_groups() ) : bp_the_profile_group();
    
    --- blah---

    Line 75 sit this placeholder do_action( 'bp_custom_profile_edit_fields_pre_visibility' ); where you can hook your additionnal information.

    Line 98 there’s another one: do_action( 'bp_custom_profile_edit_fields' ); just above this function:

    <p class="description"><?php bp_the_profile_field_description(); ?></p>

    In register.php, the section you speak about goes from line 50 to 112
    From /***** Extra Profile Details ******/ to </div><!-- #profile-details-section -->

    Of course, you can also add your own placeholder to your register template.

    Sorry if i’m wrong.

    #184071

    In reply to: Help with profiles

    danbp
    Moderator

    It’s a field builder plugin, not a filter, so no it wouldn’t help you. BuddyPress already do this (building fields and fields section) for xprofile component, so such a plugin is not to use with BP.

    Conditionnal fields is an old and remaining “must have” thing, but the state of the art is far away i guess.
    https://buddypress.org/support/topic/buddypress-conditional-profile-fields-available-now/

    i would take a try over Gravity Form at your place.

    danbp
    Moderator

    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' );
Viewing 6 results - 1 through 6 (of 6 total)
Skip to toolbar