MyBB Community Forums

Full Version: [REQUEST] Show name MyCode
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
For example, if you typed:
[name]
It would display whoever is viewing the thread's name.

ex: Chris-h11 If I was viewing the thread
or BillyBobJoe if someone named BillyBobJoe was viewing the thread
You can find something similar here. It's for RC4, but It'll work for 1.0 too.
http://mods.mybboard.com/view.php?did=7
meh... I made one anyway. Just upload the attachment to your plugin folder and activate it
Lol you forgot to change the the plugin name/version at the top of my plugin file Toungue

You can slim this down:
function namebbcode_run($message)
{
	global $db, $mybb;
	if($mybb->user['uid'] == 0)
	{
		$username[1] = "Guest";
	}
	else
	{
	$username = mysql_fetch_row($db->query("SELECT * FROM ".TABLE_PREFIX."users WHERE uid = '".$mybb->user['uid']."' LIMIT 1"));
	}
	return preg_replace("#\[name\]#sie", $username[1], $message);
}

To
function namebbcode_run($message)
{
	global $mybb;
	$username = ($mybb->user['uid'] > 0) ? $mybb->user['username'] : 'Guest';
	return preg_replace("#\[name\]#i", $username, $message);
}

Saves a query Wink
ahhh...thanks Wink I didnt know how to replace text in a post so I used your google code Wink
You can probably get away with
str_replace("[name]", $username, $message);

I think str_replace is faster than preg_replace...
your right Smile