Skip to:
Content
Pages
Categories
Search
Top
Bottom

problem about change username


  • fptquangngai
    Participant

    @fptquangngai

    I am using buddypress on my website, and when a user send’s a message its shows the real name of user and not the username, i want it to be username. I did go through the code for messages in bp-messages-template

    function bp_message_get_recipient_tabs() {
    	$recipients = explode( ' ', bp_get_message_get_recipient_usernames() );
    	
    	foreach ( $recipients as $recipient ) {
    		$user_id = bp_is_username_compatibility_mode() ? bp_core_get_userid( $recipient ) : bp_core_get_userid_from_nicename( $recipient );
    		if ( $user_id ) : ?>
    
    			<li id="un-<?php echo esc_attr( $recipient ); ?>" class="friend-tab">
    				<span><?php
    					echo bp_core_fetch_avatar( array( 'item_id' => $user_id, 'type' => 'thumb', 'width' => 15, 'height' => 15 ) );
    					echo bp_core_get_userlink( $user_id );
    				?></span>
    			</li>
    
    		<?php endif;
    	}
    }

    But this shows it is picking up username and not the real name. Can anyone tell me where to make a change so that it displays the username and not the real name of person.
    Thanks!

Viewing 1 replies (of 1 total)

  • bringmesupport
    Participant

    @bringmesupport

    Hi @fptquangngai,

    I am assuming you are referring to the name shown in the screenshot below:

    Screenshot

    This name you want to change is coming from the line bp_core_get_userlink( $user_id ); in the snippet you provided, which is part of the bp_message_get_recipient_tabs() function defined in the BuddyPress plugin under bp-members > admin > bp-members-functions.php.

    It seems there are two things you can do here:

    1. You can replace the bp_core_get_userlink() function in the message template (located at wp-content\plugins\buddypress\bp-templates\bp-legacy\buddypress\members\single\messages\compose.php) with your own custom function. See BuddyPress Codex for how to properly do this.

    OR

    2. Create a filter.

    Since the bp_core_get_userlink() function uses the ‘bp_core_get_userlink’ filter for the returned value, you can hook into this filter and modify it in your theme’s functions.php file (or your own custom plugin). The only problem is that since the bp_core_get_userlink() function is used in other parts of the code (notably the BuddyPress Login Widget), you will have to make it so that the custom filter is used only under certain conditions.

    Here is the custom filter I came up with. Its not refined, but serves as a working example:

    
    add_filter( 'bp_core_get_userlink', 'my_bp_filter', 10, 2 );
    function my_bp_filter( $string, $user_id ){  
        global $pagename;
        if ( isset( $_GET['r']) && $pagename === 'compose' ){
            $username = bp_core_get_username( $user_id );
            if ( $_GET['r'] === $username ) {
                $string = explode(' ', $string);
                $string = $string[0]. ' '. $string[1]. 'Alt="' . $username . '">'. $username . '</a>';
            }
        }
        return $string;
    }
    
Viewing 1 replies (of 1 total)
  • The topic ‘problem about change username’ is closed to new replies.
Skip to toolbar