MyBB Community Forums

Full Version: Change forumdisplay_thread hook
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I was just wondering what people thought about this - I found it when I was trying to fix a bug in a module...

In forumdisplay.php, the hook

if(is_array($threadcache))
{
	foreach($threadcache as $thread)
	{
		$plugins->run_hooks("forumdisplay_thread");

...is slightly useless. The only reason why I can see that being there is to affect the $thread variable in the loop, and because it isn't passed into the hook, it really can't do anything. The only practical workaround is an str_replace, and if you have 50 threads in a display, then that takes it's toll.

It would be much, much, easier if the the hook was:

$plugins->run_hooks_by_ref("forumdisplay_thread", $thread);

...just like the posts and PMs. What do people think?...
I think you forgot about globals. In your hook function you can just declare "global $thread;" and thus access and modify the variable directly. All MyBB hooks work that way - you will not find run_hooks_by_ref anywhere in MyBB/*.php, you'll find it used only occasionally where a variable is not global, such as in a subroutine or class of one of the MyBB/inc/*.php files.
No, I didn't forget about globals. I spent 4 hours this afternoon trying out everything. The first thing I did was globals.

Turns out it was an error in our servers' PHP build and the way MyNetwork is coded. For some strange reason, globalising $thread didn't work (and only _by_ref did it work), but upgrading the server to 5.3.0 seems to work...
Yea, if globalizing it doesn't work then you have a bug in PHP.

For some reason you always have lots of odd problems with your server setups Tom :\
Yeah don't I know it... one of the IT guys had tried to upgrade to 5.3, but epically failed, and compiled PHP wrong trying to revert his changes. Genius.

Anyway, my new private server arrives this week so fingers crossed everything works good. Shy
I don't find it useless, I've used it on two plugins already (by globalizing $thread) and without it, I couldn't have coded them Toungue