Advertisement:

Author Topic: Username instead of real name for comments  (Read 140 times)

abeasse

  • Newbie
  • *
  • Posts: 2
Username instead of real name for comments
« on: January 10, 2019, 11:28:08 pm »
Hello,

I would like show the username (nickname) instead of the real name when someone posts a message.

In item.php, the "AuthorName" is loaded by osc_logged_user_name() :

Code: [Select]
<input type="hidden" name="authorName" value="<?php echo osc_esc_htmlosc_logged_user_name() ); ?>" />
I tried to create a new function in helper hUsers.php called osc_logged_user_username() but it doesn't work (i'm beginner).

Please, help me  ;)


patrickFromCroatia

  • Hero Member
  • *****
  • Posts: 655
  • Best profile picture plugin ever is coming!
Re: Username instead of real name for comments
« Reply #1 on: January 11, 2019, 01:21:46 am »
Hello,

I was searching and can't actually find a helper for this, but you can do it this way:

Create a function in your functions.php:

Code: [Select]
<?php
function wm_logged_user_username() {
    
$id osc_logged_user_id();
    
$user User::newInstance()->findByPrimaryKey($id);
    
$username $user['s_username'];
    
    return 
$username;
}
?>


And then you can use "wm_logged_user_username()" to get the user name of the logged user.

If you need help putting that code in your theme, post the theme name.

Regards.

abeasse

  • Newbie
  • *
  • Posts: 2
Re: Username instead of real name for comments
« Reply #2 on: January 12, 2019, 07:59:03 pm »
It works very well !

Thank you very much  ;)