How to display the username instead of the first name and the last name ?

OSSN USER Posted in General Discussion 7 years ago

Hi,

I would like to know how to display the username instead of the first name and the last name on the network ?

Thanks
OSSN User

Replies
us Rishi B Replied 5 years ago

good point, I hadn't seen than component, thanks Arsalan.

Indonesian Arsalan Shah Replied 5 years ago

@Bansh, he don't need to edit the stuff, he can use the already exsiting component : https://www.opensource-socialnetwork.org/component/view/3065/display-username

us Rishi B Replied 5 years ago

another possibility that might help you would be to edit the fullname property of the OssnUser class. I'm really not sure if this would take care of it for all occurrences network wide or not. It's line 178 of classes/OssnUser.php:

$user->fullname   = "{$user->first_name} {$user->last_name}";

you can set it to whatever you want, for example $user->fullname = $user->username;

I'm honestly not sure if that would take care of it network-wide or not though, feel free to try it out, just back up your files first as I mentioned in my last post.

us Rishi B Replied 5 years ago

if you feel searching for "->firstname" is sketchy, it might be easier for you to identify exactly what places you want to replace this in. For example, if you want to replace this in the Profile screen you could edit components/OssnProfile/default/plugins/profile/pages/profile.php. You'll see many occurrences of ->fullname (and probably ->firstname too). Replace with "->username". Repeat for each screen as you see fit. You should probably also backup each file before editing it if you aren't terribly comfortable with php.

us K Martin Replied 5 years ago

I would also like to do this. I tried the code snippet Arsalan Shah posted, but it sent my site into whitescreen. Searching and replacing firstname seems kinda sketchy. Surely there is a better way to get a user's username to appear instead of their first and last names. No?

Indonesian Arsalan Shah Replied 7 years ago

You can try following code in your ossn_com.php file.

function firstname_username_init(){
    ossn_add_hook('user', 'get', 'ossn_clone_firstname_username');
}
function ossn_clone_firstname_username($hook, $type, $return, $params){
        $return->fullname= $return->username;
        return $return;
}
ossn_register_callback('ossn', 'init', 'firstname_username_init');
Indonesian Arsalan Shah Replied 7 years ago

The one of the way is to search for ->firstname in components directory and replace it to ->username however this will break some settings for profile edit page... So you have to look into each file one by one (in components directory)