MyBB Community Forums

Full Version: Hooks with arguments
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I am trying to get my head around the hooks with arguments and just can't do it.

I have read through http://docs.mybb.com/Plugins-The_Hook_System.html but its still not making sense to me.

Basically what I want to do is alter the redirect message for certain users.

Can anyone show me a decent working example of point me to a plugin that uses the hooks with arguments so I can try to figure it out?

Cheers
Dan

Reallly all I am trying to do is alter the $message or the redirect

I tried to use $message = $plugins->run_hooks("redirect", $message);

but this still returned blank
You should look at existing plugins to see how hooks work. Some of them use arguments for sure.
Cheers, I haven't found any plugins that use those args and didn't want to go through and just keep downloading plugins till I found one, so do you know any specific ones that uses a hook with args? Or can you provide me with a snippet?
I'm not entirely sure what you're trying to do. Are you trying to use a hook or add a new hook?
$plugins->add_hook("redirect", "add_to_redirect");

function add_to_redirect(&$redirect_args)
{
global $lang;

	$new_content = "XXXXXXXXXXXXXX";

	if($redirect_args['message'] != '')
	{
		$redirect_args['message'] .= '<br /><br />'.$new_content;
	}
	else
	{
		$redirect_args['message'] = $lang->redirect.'<br /><br />'.$new_content;
	}
}
(2012-08-02, 05:59 PM)Pirata Nervo Wrote: [ -> ]I'm not entirely sure what you're trying to do. Are you trying to use a hook or add a new hook?

No On the redirect I am trying to alter the message that is displayed on the fly depending on post count.


(2012-08-02, 08:05 PM)pavemen Wrote: [ -> ]
$plugins->add_hook("redirect", "add_to_redirect");

function add_to_redirect(&$redirect_args)
{
global $lang;

	$new_content = "XXXXXXXXXXXXXX";

	if($redirect_args['message'] != '')
	{
		$redirect_args['message'] .= '<br /><br />'.$new_content;
	}
	else
	{
		$redirect_args['message'] = $lang->redirect.'<br /><br />'.$new_content;
	}
}

That looks like what I am after. I will test it out cheers.

Dan