Skip to:
Content
Pages
Categories
Search
Top
Bottom

[Resolved] Nobody visibility

  • Avatar of csimpson
    csimpson
    Participant

    @csimpson

    Hi all, can someone clear this up for me please?

    The Nobody field visibility in buddypress – I understand its a field which is against a users profile of which only the admins can see. This is exactly what i am after. I need a place for an admin to make notes against a user, of which the user cannot see.

    I’ve seen so much talk about this field, although fairly old now, but seems like it has been finally developed in bp 2.0+.

    However, it doesnt work for me. I have a field called ‘notes’.

    Should this feature now work and for some reason my installation isn’t/conflicting etc. I am also using xprofile fields.

    best wishes Craig

Viewing 6 replies - 1 through 6 (of 6 total)
  • Avatar of henrywright
    henrywright
    Moderator

    @henrywright

    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

    Avatar of danbp
    danbp
    Moderator

    @danbp

    @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');
    Avatar of danbp
    danbp
    Moderator

    @danbp

    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' );
    Avatar of shanebp
    shanebp
    Moderator

    @shanebp

    @csimpson

    You may be interested in one of my premium plugins: BuddyNotes

    It allows site admins to make notes per member.

    Avatar of henrywright
    henrywright
    Moderator

    @henrywright

    Very nice plugin @shanebp!

    Avatar of csimpson
    csimpson
    Participant

    @csimpson

    wow, thanks for help everyone. I will investigate both plugin and other options. best wishes craig

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

The topic ‘[Resolved] Nobody visibility’ is closed to new replies.