BuddyDev

Search

[Resolved] @mention with full name

  • Participant
    Level: Initiated
    Posts: 13
    Plamen Peev on #24685

    Hi,

    Is there a way to display @mention with user’s full name instead of username?
    It needs to be unique and I get it so can we use username for filtering
    and full name to just display it when selected?

    Thanks

  • Keymaster
    (BuddyDev Team)
    Posts: 21806
    Brajesh Singh on #24719

    Hi,
    Thank you for the question.

    Even though it is doable, It will need extra efforts from you.

    1. A plain text area can not have a different content presentation than the content view. What you want if you use contenteditable div or rich text area. They can have 2 different views. This will need rewriting the part of theme that provides interface for posting content(and related js)

    2. Filtering the displayable content:- Filtering @ mentioned username at the time of display of activity content is inefficient as you will need to use regular expression to achieve the same for each entry. You can hook to activity saving action and update content to use the display name for mentioned users. Make sure to hook a bit late to allow the activity mention notificationss work.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 13
    Plamen Peev on #24739

    Thanks, Brajesh,

    Found that I can control the output from here:

    ‘// Replace @mention text with userlinks.
    foreach( (array) $usernames as $user_id => $username ) {
    $activity->content = preg_replace( ‘/(@’ . $username . ‘\b)/’, “@$username“, $activity->content );’
    }

    Changing $username to $display_name does not work however.

    • This reply was modified 3 years, 1 month ago by Plamen Peev.
  • Keymaster
    (BuddyDev Team)
    Posts: 21806
    Brajesh Singh on #24794

    Hi Palmen,
    you may want to use

    
    
    bp_core_get_user_displayname( $user_id )
    
    

    Instead of the $username. Something like this

    
    $activity->content = preg_replace( '/(@' . $username . '\b)/', bp_core_get_user_displayname( $user_id ), $activity->content );
    
    

    may work.

    Regards
    Brajesh

  • Participant
    Level: Initiated
    Posts: 13
    Plamen Peev on #24865

    Brajesh, thanks a lot, it’s working 🙂 Now I only need to figure out how to incorporate the link to the profile and the @ 🙂 Thanks a lot for the tip! Appreciate it!

You must be logged in to reply to this topic.

This topic is: resolved