MyBB Community Forums

Full Version: {$mybb->user['usertitle']} on Index Page
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello everyone,

Running latest version of MyBB.

In my index template, I have the "{$mybb->user['usertitle']}" variable. If there is a default user title for the group of the current user, then it displays properly. However, if this is left empty, and the user title is subsequently taken from the user titles list in the ACP, then the variable generates nothing; the user title is just blank.

For example:
[Image: 22CcNqe.png] Yields [Image: Jm4fVWT.png]

[Image: M8xQFrZ.png] + [Image: OkmvTd8.png] Yields [Image: gEGnMtf.png]

Why is the user title not being rendered?
To clarify, it's working fine in the postbit and memberprofile.
It's because of how the usertitles are loaded in different places. For the member profile and postbit, it loads it for the specific user, falling back to the usergroup, and then falling back to any user titles you've added. However, for the value available globally for the currently logged in user (which is what you're using), it only falls back to the usergroup usertitle.
(2020-12-08, 06:22 PM)Matt Wrote: [ -> ]It's because of how the usertitles are loaded in different places. For the member profile and postbit, it loads it for the specific user, falling back to the usergroup, and then falling back to any user titles you've added. However, for the value available globally for the currently logged in user (which is what you're using), it only falls back to the usergroup usertitle.

Thank you for the response. How would I get this value to show on the index then? Is there no "stock" way to do this?

The "{$usergroup['usertitle']}" variable also does the same thing.
It would either need a plugin or a core file edit to do it. As a core edit:

In ./inc/class_session.php, line 317:

if(!$mybb->user['usertitle'])
{
	$mybb->user['usertitle'] = $mybb->usergroup['usertitle'];
}

After this, add:

if(!$mybb->user['usertitle'])
{
	$usertitles = $cache->read('usertitles');

	if(is_array($usertitles))
	{
		foreach($usertitles as $title)
		{
			if($mybb->user['postnum'] >= $title['posts'])
			{
				$mybb->user['usertitle'] = $title['title'];

				break;
			}
		}
	}
}

Not tested but that should work. If you like, I can wrap that up in a small plugin for you.
(2020-12-08, 06:31 PM)Matt Wrote: [ -> ]It would either need a plugin or a core file edit to do it. As a core edit:

In ./inc/class_session.php, line 317:

if(!$mybb->user['usertitle'])
{
	$mybb->user['usertitle'] = $mybb->usergroup['usertitle'];
}

After this, add:

if(!$mybb->user['usertitle'])
{
	$usertitles = $cache->read('usertitles');

	if(is_array($usertitles))
	{
		foreach($usertitles as $title)
		{
			if($mybb->user['postnum'] >= $title['posts'])
			{
				$mybb->user['usertitle'] = $title['title'];

				break;
			}
		}
	}
}

Not tested but that should work. If you like, I can wrap that up in a small plugin for you.

Thank you so much, the edit does indeed work. Is there a similar solution I can use for "{$usergroup['usertitle']}" as well?

Edit: I'm realizing how that variable is different now. Was mixing them up, sorry. What I meant was: is there a way to get that variable to fall back to the other usertitles as well?