Current Logged In User's Username and Avatar

Discussion forum for MOD Writers regarding MOD Development.
Locked
GoremanX
Registered User
Posts: 27
Joined: Wed Apr 21, 2010 5:44 am

Current Logged In User's Username and Avatar

Post by GoremanX »

I'm trying to find the variable that will give me the current logged in user's username. I assumed it would be {USERNAME}, but that returns nothing. I tried {L_USERNAME}, but that just returns the English word for Username (which is, unsurprisingly, Username}. I tried {U_USERNAME}, but I get nothing from that.

I'd also like to know what variable will give me a url to the current logged in user's avatar.

Thanks,
User avatar
3Di
Former Team Member
Posts: 16052
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milano 🇮🇹 - Frankfurt 🇩🇪
Name: Marco
Contact:

Re: Current Logged In User's Username and Avatar

Post by 3Di »

the function get_user_avatar takes care (you bet?) of the user's avatar. (includes/functions_display.php)

the function get_username_string takes care of the user's name. (includes/functions_content.php)

hope this helps
To request support for our extensions you can also contact me here: phpBB Studio

Please PM me only to request paid works. Thx. Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
🚀 Looking for a specific feature or alternative option? We will rock you! 🚀
GoremanX
Registered User
Posts: 27
Joined: Wed Apr 21, 2010 5:44 am

Re: Current Logged In User's Username and Avatar

Post by GoremanX »

But those require that I supply a specific user ID. Surely there must be some simpler way of displaying the current user's name on the page. It's only for a dead-simple "Hi, {USERNAME}" thing with their avatar next to it....
User avatar
3Di
Former Team Member
Posts: 16052
Joined: Mon Apr 04, 2005 11:09 pm
Location: Milano 🇮🇹 - Frankfurt 🇩🇪
Name: Marco
Contact:

Re: Current Logged In User's Username and Avatar

Post by 3Di »

1 - $user->data['username'] gives you the user name

2 - $user->data['user_avatar'] gives you the phpbb location/filename of the user's avatar image

depending on where you are bound to use these you maybe need to use also:

Code: Select all

define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.'.$phpEx);
$user->session_begin();
To request support for our extensions you can also contact me here: phpBB Studio

Please PM me only to request paid works. Thx. Want to compensate me for my interest? Donate
My development's activity º PhpStorm's proud user º Extensions, Scripts, MOD porting, Update/Upgrades
🚀 Looking for a specific feature or alternative option? We will rock you! 🚀
GoremanX
Registered User
Posts: 27
Joined: Wed Apr 21, 2010 5:44 am

Re: Current Logged In User's Username and Avatar

Post by GoremanX »

ah hah! That worked well. I added this to the php file of the login mod I'm using:

Code: Select all

$template->assign_var('CURRENT_USERNAME', $user->data['username']);
and now adding {CURRENT_USERNAME} within that mod makes the current logged-in user's username appear.

Thanks!
Locked

Return to “[3.0.x] MOD Writers Discussion”