I'm in the process of writing plugins to modify the displayed username of anyone who has an email address in their username. I have it working fine in several places, but I'm stuck on how to get it working on the "Last Post" part of the main forum listing on the homepage. I've tried every variation on the following code that I can find. The code works and properly modifies the variables I'm targeting, but no matter what I do, the templates still display the unmodified version of the lastposter username.
I've got the following code attached to the "forumbit_display" hook...
Code:
if($pos=strpos($lastpostinfo['lastposter'],"@"))
{
$lastpostinfo['lastposter']= substr($lastpostinfo['lastposter'],0,$pos);
}
I've also tried modifying the $vbulletin object variables and every other variable I can think of and tried several other hooks, but I'm getting nowhere. The variables are modified properly in every place I've done it, but they still don't display modified in the templates. I will worship whoever can figure this out! In the meantime, I've written a dirty hack that just does a preg_replace on the $forumbits...
Code:
// Attached this dirty code to forumhome_complete hook.
//There's got to be a better way than doing this preg_replace
$forumbits=preg_replace("/([a-zA-Z0-9]+)(@)([a-zA-Z_\-.]+)/","$1",$forumbits);
It's working, but I'd rather find the proper variable to modify and alter the values before they are added to the $forumbits.
EDIT: I've got it working properly now!!! I could have sworn I tried this already, but I attached the following code to the "forumbits_display" hook and suddenly it works:
Code:
foreach($vbulletin->forumcache as $k=>$v)
{
if($pos=strpos($v['lastposter'],"@"))
{
$vbulletin->forumcache[$k]['lastposter']= substr($v['lastposter'],0,$pos);
}
}
Strange. Maybe I was having caching issues last time I tried the code. I'm having a really hard time figuring out which variables to tweak to get things to show up in the templates. There seems to be quite a bit of duplicate variables with the same data in different places. For this hack I was messing with $forum['lastposter'], $lastpostinfo, and $vbulletin (among others). I wish there was just a single location I could go to tweak the values. I'm still trying to figure out if $vbulletin->forumcache is just a cached version of the forums or if it is updated on every page load. I'm going to assume it is the main forum datastore for the rest of my plugin work unless someone sets me straight.