Jump to the post that solved this thread.
Solved: 7 Months, 2 Weeks, 6 Days ago {$mybb->user['usertitle']} on Index Page
#1
Solved: 7 Months, 2 Weeks, 6 Days ago
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.
Reply
#2
Solved: 7 Months, 2 Weeks, 6 Days ago
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.
MyReactions - All Plugins

Can you still feel the butterflies?

Free never tasted like pudding.
Reply
#3
Solved: 7 Months, 2 Weeks, 6 Days ago
(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.
Reply
#4
Solved: 7 Months, 2 Weeks, 6 Days ago
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.
MyReactions - All Plugins

Can you still feel the butterflies?

Free never tasted like pudding.
Reply
#5
Solved: 7 Months, 2 Weeks, 6 Days ago
(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?
Reply
Jump to the post that solved this thread.


Forum Jump:


Users browsing this thread: 1 Guest(s)