MyBB Community Forums

Full Version: Create profile link from UID
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm trying to get an user profile link with username, like this:

<a href="https://community.mybb.com/user-85856.html">ShadowOne</a>

But I need to do so for specific UIDs, like

$user= "<a href=\"{$mybb->settings['bburl']}/".get_profile_link($serial['uid'])."\">Username</a>";

Where
Quote:$serial['uid']

Is a specific user UID, taken from a table in mybb database.
It works, but I don't know which mybb variable should be used instead of "Username" to display the specific username, given the uid inside my table  Sad


EDIT:

Checking between Mybb functions I've come across function build_profile_link which is defined like this from functions.php

function build_profile_link($username="", $uid=0, $target="", $onclick="")
{
	global $mybb, $lang;

	if(!$username && $uid == 0)
	{
		// Return Guest phrase for no UID, no guest nickname
		return htmlspecialchars_uni($lang->guest);
	}
	elseif($uid == 0)
	{
		// Return the guest's nickname if user is a guest but has a nickname
		return $username;
	}
	else
	{
		// Build the profile link for the registered user
		if(!empty($target))
		{
			$target = " target=\"{$target}\"";
		}

		if(!empty($onclick))
		{
			$onclick = " onclick=\"{$onclick}\"";
		}

		return "<a href=\"{$mybb->settings['bburl']}/".get_profile_link($uid)."\"{$target}{$onclick}>{$username}</a>";
	}
}

Do you think it be adapted so that only UID is passed, via $serial['uid'] ?
You need to pass the username as well, the function won’t get it for you.
(2020-12-02, 07:17 PM)Omar G. Wrote: [ -> ]You need to pass the username as well, the function won’t get it for you.

There's no pre-built Mybb function that returns me an username, given an user id? Sad
Try get_user()
$uid = 56; // Say ...
$user = get_user($uid);
$userlink = build_profile_link($user['username'], $uid);
(2020-12-03, 05:26 AM)effone Wrote: [ -> ]Try get_user()
$uid = 56; // Say ...
$user = get_user($uid);
$userlink = build_profile_link($user['username'], $uid);

It worked!! Thank you so much for your help!