Users running a non-download version of Vanilla (pulled from github), on branch release/2019.016 or master from the last 2 weeks should upgrade to release/2019.017 or latest master for security reasons. Downloaded official open sources releases are not affected.

Show a display name instead of username

2»

Comments

  • R_JR_J Cheerleader & Troubleshooter Munich Moderator

    Forget everything else and add this two lines to your /conf/config.php:

    $Configuration['Garden']['User']['ValidationRegex'] = '\\d\\w-_ äöüß';
    $Configuration['Garden']['User']['ValidationLength'] = '{3,20}';
    

    That way your users are able to choose whatever user name they like.
    You only need the second line if you want to change the max. length of a name

    If you want to give your users the ability to "fix" their names, add the following line to the config: $Configuration['Garden']['Profile']['EditUsernames'] = true;
    I would announce that possibility of changing the name and make it available for a restricted time.


    timme2707vintprox
  • Thanks @R_J !

  • vintproxvintprox New
    edited March 25

    YES! Thank you, goodness! I was finding such solution whole day. It makes a trick for me in theme hook. I slightly modified it to fallback to username if display name was not set:

    <?php if (!defined('APPLICATION')) exit;
    
    
    class ForumThemeHooks implements Gdn_IPlugin {
        public function setup() {
            return true;
        }
    }
    
    
    if (!function_exists('userAnchor'))
    {
        function userAnchor($User, $CssClass = null, $Options = NULL)
        {
            static $NameUnique = null;
            if ($NameUnique === null) {
                $NameUnique = c('Garden.Registration.NameUnique');
            }
            if (is_array($CssClass)) {
                $Options = $CssClass;
                $CssClass = null;
            } elseif (is_string($Options)) {
                $Options = array('Px' => $Options);
            }
            $Px = val('Px', $Options, '');
            $DisplayName = GetUserDisplayName($User);
            $Text = val('Text', $Options, htmlspecialchars($DisplayName));
            $Attributes = array(
                'class' => $CssClass,
                'rel' => val('Rel', $Options)
            );
            if (isset($Options['title'])) {
                $Attributes['title'] = $Options['title'];
            }
            $UserUrl = userUrl($User, $Px);
            return '<a href="'.htmlspecialchars(url($UserUrl)).'"'.attribute($Attributes).'>'.$Text.'</a>';
        }
    
    
        function GetUserDisplayName($User)
        {
            $DisplayName = $User->Name;
            $SQL = Gdn::sql();
            $SQL
                    ->Select('u.Value')
                    ->From('UserMeta u')
                    ->Where('u.UserID', $User->UserID)
                    ->Where('u.Name', "Profile.Fullname");
            
            $UserMeta = $SQL->Get()->FirstRow();
            if (isset($UserMeta->Value) and !empty($UserMeta->Value)) {
                $DisplayName = $UserMeta->Value;
            }
            return $DisplayName;
        }
    }
    
    

    Well, yeah, activity titles are not affected by it as you noted. Seems like a problem with Vanilla+Smarty user modifier (applications/dashboard/views/activity/helper_functions.php, line 30, function Gdn_Format::to), but as expected behavior users mentioned in activity should convert to userAnchor result, but no luck today.

Sign In or Register to comment.