Skip to:
Content
Pages
Categories
Search
Top
Bottom

Search Results for 'hide fields'

Viewing 25 results - 76 through 100 (of 260 total)
  • Author
    Search Results
  • ChiefAlchemist
    Participant

    => re: “Note that you need to add the correct id(s) for exclude_fields.”

    Thanks shanebp. But is this the only way? I mean, I can’t do mucking with the code every time the client wants something new? Can I?

    => re: …/buddypress-xprofile-custom-fields-type/

    “Add new visibility setting “Nobody”. Hide the field to all members.”

    So this means, I presume that custom visibility is possible. Yes?

    That said, I want to use standard fields, but I want to create the list via code, and not have to do it manually. Not possible? Mind you, it could be cause I’m new to BP but I’m trying to where / how the profile definitions are stored. I presume it’s an array, or close. So I want to do that but with code.

    Thanks again

    shanebp
    Moderator

    I wouldn’t rely on messing with visibility settings.
    To make a profile field only editable by admins, do this in bp-custom.php or a plugin:

    // only admins can edit the Skills field
    function chief_hide_profile_fields( $retval ) {
    	
    	if( is_super_admin () )
    		return $retval;
    
    	if(  bp_is_profile_edit() || bp_is_register_page() )
    		$retval['exclude_fields'] = '3';	//profile field ID's separated by comma
    
    	return $retval;
    
    }
    add_filter( 'bp_after_has_profile_parse_args', 'chief_hide_profile_fields' );

    Note that you need to add the correct id(s) for exclude_fields.
    And that ‘ || bp_is_register_page() ‘ keeps the field(s) off the register page – which you may not need to do.

    Re how to create profile fields in code, there a couple of ways to do it depending on the kind of field and how it will be used.
    Take a look at these plugins for more info:
    https://wordpress.org/plugins/buddypress-xprofile-custom-fields-type/
    https://wordpress.org/plugins/buddypress-xprofile-image-field/

    shanebp
    Moderator

    try this in bp-custom.php.
    You’ll have to get the ids of the fields you want to exclude on the register page

    function register_hide_profile_fields( $retval ) {
         if( bp_is_register_page() )
    	  $retval['exclude_fields'] = '3';  //field ID's separated by comma
    
         return $retval;
    
    }
    add_filter( 'bp_after_has_profile_parse_args', 'register_hide_profile_fields' );
    #188504
    danbp
    Participant

    Another snippet, more accurate with the suggested way above. Snippet goes into bp-custom or functions.php

    The field/field group is only shown to site admins. A small bug in the current BP version(.0 -> 2.0.2) prevent of completely remove the group tab from the edit screen. Bug is fixed and this will work with BP 2.1.

    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'] = '60';  
    		//exlude groups, separated by comma - this may work with BP 2.1
    		$retval['exclude_groups'] = '7'; 			
    	} 
    	return $retval;		
    	
    	endif;
    }
    add_filter( 'bp_after_has_profile_parse_args', 'bpfr_hide_profile_field_group' );
    #188500
    danbp
    Participant

    @csimpson,

    oh crossposting ! haven’t seen henry’s answer.

    nobody visibility doesn’t exist. This setting is called “only me“. This means that only the member can see this field – and the site admins. Such fields are not for site admins, but for the members !

    I don’t really understand what is not working for you, as what you’re looking for doesn’t exist in BuddyPress. Sorry if i’m misunderstanding you.

    When you create such a field visibility, you should also set “Enforce the default visibility for all members“, so the member cannot modify it later on his profile settings.

    Little weird side effect, when a “only me” field is used and member A wrote hello, this word becames clickabke, by default. When member B write also hello, it becames also clickable. And if A or B clcik on Hello, it shows a list of all members who wrote the same word. In this case A and B !

    Not really confidential, isn’t it ? The solution is to remove the clickable link.
    Here’s a snippet which let you do that selectively.

    function my_xprofile_filter_link_profile_data( $field_value, $field_type = 'textbox' ) {
        // Access the field you are going to display value.
        global $field;
    	
        // In this array you write the ids of the fields you want to hide the link.
        $excluded_field_ids = array(2,9,54); // field ID separated by comma
    	
        // If the id of this $field is in the array, we return the value only and not the link.
        if (in_array($field->id, $excluded_field_ids))
    	return $field_value;
    
    	if ( 'datebox' == $field_type )
    	return $field_value;
    	
    	if ( !strpos( $field_value, ',' ) && ( count( explode( ' ', $field_value ) ) > 5 ) )
    	return $field_value;
    	
    	$values = explode( ',', $field_value );
    
    	if ( !empty( $values ) ) {
    		foreach ( (array) $values as $value ) {
    			$value = trim( $value );
    			
    			// If the value is a URL, skip it and just make it clickable.
    			if ( preg_match( '@(https?://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?)@', $value ) ) {
    				$new_values[] = make_clickable( $value );
    				
    				// Is not clickable
    			} else {
    				
    				// More than 5 spaces
    				if ( count( explode( ' ', $value ) ) > 5 ) {
    					$new_values[] = $value;
    					
    					// Less than 5 spaces
    				} else {
    					$search_url   = add_query_arg( array( 's' => urlencode( $value ) ), bp_get_members_directory_permalink() );
    					$new_values[] = '<a href="' . $search_url . '" rel="nofollow">' . $value . '</a>';
    				}
    			}
    		}
    		
    		$values = implode( ', ', $new_values );
    	}
    	
    	return $values;
    }
    
    /**
     * We remove the buddypress filter and add our custom filter.
     */
    function remove_xprofile_links() {
        // Remove the old filter.
        remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 );
        // Add your custom filter.
        add_filter( 'bp_get_the_profile_field_value', 'my_xprofile_filter_link_profile_data', 9, 2);
    }
    add_action('bp_setup_globals', 'remove_xprofile_links');
    #188499
    Henry Wright
    Moderator

    I think the field visibility settings are applicable to the member who is performing the setting.

    The suggested way to do what you want would be to make your notes profile field hidden to all non-admin members.

    The first step would be to create /wp-content/themes/your-theme/buddypress/members/single/profile/edit.php inside your theme.

    You can copy the contents of edit.php from:

    bp-templates/bp-legacy/buddypress/members/single/profile/edit.php

    Then you need to modify edit.php. In edit.php, find <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?> and add the following immediately after it:

    if ( ! current_user_can( 'manage_options' ) && ( bp_get_the_profile_field_name() === 'notes' ) )
        continue;

    Note: I’m assuming your field name is notes

    danbp
    Participant

    Hi @ww2boy,

    Yes ! πŸ˜‰ Give this a try. Add it to child theme’s functions.php or bp-custom.php

    function bpfr_hide_profile_edit( $retval ) {	
    	// remove field from edit tab
    	if(  bp_is_profile_edit() ) {		
    		$retval['exclude_fields'] = '54'; // ID's separated by comma
    	}	
    	// allow field on registration page     
    	if ( bp_is_register_page() ) {
    		$retval['include_fields'] = '54'; // ID's separated by comma
    		}		
    	
    	// hide the filed 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' );

    Codex reference:
    https://codex.buddypress.org/plugindev/using-bp_parse_args-to-filter-buddypress-template-loops/

    mrapino
    Participant

    Okay, this is my first piece: http://pastebin.com/pyz8XaaP

    This first link is some code findings that might continue the conversation toward an elegant solution.

    And then I came up with another possible solution here, which is actually partially working, but might be a bit clunky: http://pastebin.com/3JBCuZrx

    Basically, the first link is not working, but may give us more food for thought. The second link is working, but there are a few caveats. What I am doing in the second link is finding out what user role the logged in user is attached to. Then I create a conditional that states that if the user is under a certain role, it hides the profile group tabs from being seen, which essentially prevent them from adding content to them, and if there is no content for any of the fields in the group, it won’t show on the front end.

    CAVEAT: if you go directly to the profile group URL, you can still edit. I need to figure out how to actually prevent the URL from working, as opposed to/ or in addition to hiding it.

    Either way, I think there’s a bunch of good stuff to talk about here.

    Let me know what you think.

    NOTE: I am using some code found on this post:
    https://buddypress.org/support/topic/conditional-exclusion-of-a-xprofile-fields-group-from-editing/

    mrapino
    Participant

    Thanks for the links.

    Defining a role doesn’t necessarily require previous input from the people using your site … you simply define the roles of your users based on what you want those users to be. Custom user roles allow you to have more granular control over what your users can do and see when registered on your site. Regarding Buddypress … I think that having a way to pre-define user types/roles and assigning custom profiles to those various user types is something to be desired.

    I am using Gravity Forms to create a custom registration form that allows a registrant to pick the type of user they are and when the user type is chosen, I am conditionally displaying custom fields that are associated to the specific user type.

    The problem is that after the user registers, and the fields are filled out, if they go to their profile to edit the information, they see ALL FIELDS regardless of the user role they chose during registration. The reason is that although Gravity Forms allows you to map certain fields on the form to profile fields in Buddypress, you still have to edit Buddypress to HIDE the fields you don’t want those users to see.

    That is why I am posting this question … I am trying to get code together to alter the profile section of Buddypress to allow you to associate specific profile fields to a user role, so when the user of a specific role finally goes to their profile to make edits, they do see, and are not allowed to edit fields that are not associated to their specific role.

    IMHO this type of control is very useful, as it can help you create some fairly interesting communities.

    Thanks for your assistance. I hope I have clarified things further for you. If anyone can help, great … if not, I am still moving forward on this and when I come up with a solution, I will post it here. If anyone can help me get to that solution faster, I’d be very appreciative. If not, I hope I can help those of you who are looking for the same results.

    #187041
    danbp
    Participant

    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. πŸ˜‰

    #186516
    danbp
    Participant

    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' );
    rcjr24
    Participant

    @mercime I manage to rearrange all the fields using the code I posted, and now I have a code like this,

    <?php if ( function_exists( 'bp_has_profile' ) ) : if ( bp_has_profile( 'profile_group_id=1&hide_empty_fields=0' ) ) : while ( bp_profile_groups() ) : bp_the_profile_group(); ?>
    <?php while ( bp_profile_fields() ) : bp_the_profile_field(); ?>
    <?php if ( 'Country of Residence' == bp_get_the_profile_field_name() ) : ?>
    
    	<select class="country-residence" name="<?php bp_the_profile_field_input_name(); ?>" id="<?php bp_the_profile_field_input_name(); ?>" placeholder="<?php _e( bp_the_profile_field_name().':' ); ?>">
    		<?php //bp_the_profile_field_options(); 
    			
    			global $wpdb;
    			$sql = "SELECT * FROM wp_country_list";
    			$results = $wpdb->get_results($sql) or die(mysql_error());
    			echo '<option data-value="holder-only" class="holder">Country of Residence:</option>';
    				foreach( $results as $result ) {
    
    					echo '<option data-value="'. $result->three_letter_code .'" value="'. $result->three_letter_code .'">'.$result->name.'</option>';
    				}
    		?>
    	</select>
    	<?php do_action( bp_get_the_profile_field_errors_action() ); ?>
    
    <?php endif; ?>
    <?php endwhile;  ?>
    
    <?php endwhile; endif; endif; ?>

    Now the problem is, when the registration completes, this field doesn’t reflect to the user profile after successful registration. Hope you’ve got my point here.

    #183913
    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!

    CommonEasy
    Participant
    #183740

    In reply to: Remove profile links

    CommonEasy
    Participant

    sorry to bump this old topic. I use both BP 2.0.1 and BP custom fields type and i got the the links removed with:

    function remove_xprofile_links() {
        remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 9, 2 );
    }
    add_action('bp_setup_globals', 'remove_xprofile_links');

    I was wondering if you could use this to only hide the links from certain profile fields, like only for profile field 2, 6 & 7 ?

    #183705
    compixonline
    Participant

    Hi –

    I really appreciate your reply… it’s a little above my head but working on it. How would you then populate the buddypress Xprofile fields (which would be the same, say user_meta is occupation I would have a BP Xprofile field “occupation” and I’d want to copy it across.

    I’d also want to hide the ability to change that field in the BP members profile, forcing them to use the Membermouse field in order to change their occupation both in the Membermouse Table and their BP profile…

    Hope you can help! Many thanks.

    #183636
    Iurie Malai
    Participant

    @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.

    CommonEasy
    Participant

    you should try to hide the fields from the edit profile page but not from the profile page. try editing the wwwroot/wp-content/plugins/buddypress/bp-themes/bp-default/members/single/profile/edit.php. more information here https://buddypress.org/support/topic/ow-to-hide-more-than-one-profile-field/

    #183454
    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' );
    #183453
    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 πŸ™‚

    Iurie Malai
    Participant

    @danbp, I know how to check for errors, but this didn’t helped me too much :). I solved with the blank page, but no more. Your solution works for hiding some xProfile tabs from viewing, but not from editing them. Am I wrong? Sorry!

    This is my tested function (as I said, it hiding only from viewing, not from editing):

    
    function flegmatiq_profiles( $retval ) {
    
       if ( is_user_logged_in() && !bp_is_profile_edit() ) {
          $myfield = xprofile_get_field_data( 'User Type' );
          if( $myfield == "Faculty" ) {
             $retval['exclude_groups'] = '2';
    	 //$retval['exclude_fields'] = '6,18,39';
          }
       }
    
       return $retval;
    
    }
    
    add_filter( 'bp_after_has_profile_parse_args', 'flegmatiq_profiles' );
    

    The next code works as I need, but I think it is not so elegant, and it not allow to use the group ID, only his order number, as ordered by admin:

    
    function hide_profile_group_tabs_from_editing( $group_names ){
    
       if ( is_user_logged_in() && bp_is_profile_edit() && xprofile_get_field_data( "User Type") != "Faculty" ) {
          for ($x=0; $x<=sizeof($group_names); $x++) {
             if ( $x != 3 ) echo $group_names[$x]; //3 is the order number (from 0) of the tab that I need to hide in the profile edit page. This is not the group ID.
          }
       } else {
          return $group_names;
       }
    
    }
    
    add_filter('xprofile_filter_profile_group_tabs', 'hide_profile_group_tabs_from_editing');
    
    Iurie Malai
    Participant

    @danbp, thank you! I tested your solution (the last function), but no success. Is enough to put this in the bp-custom.php file?

    I tried the next simple function to hide the extended fields group number 2 from editing for all members, but it not working.

    
    function flegmatiq_profiles( $retval ) {	
    	
    	if(  bp_is_profile_edit() ) {		
    		$retval['exclude_groups'] = '2';
    	}	
    	
    	return $retval;
    	
    }
    add_filter( 'bp_after_has_profile_parse_args', 'flegmatiq_profiles' );
    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' );
    #183117
    danbp
    Participant

    @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.

    #183085
    shanebp
    Moderator

    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';

Viewing 25 results - 76 through 100 (of 260 total)
Skip to toolbar