MyBB Community Forums

Full Version: Which hook?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I wanted to have a plugin do a calculation whenever a member posts a reply or a new thread. I tried having it go off of the datahandler_post_insert_post and datahandler_post_insert_thread hooks because I thought those would be the ones to use. I wanted to use the array that is already available in an update query for the table mybb_users to avoid an unnecessary query. So far I have had no luck.

$plugins->add_hook("datahandler_post_insert_post", "pokemon_level");
$plugins->add_hook("datahandler_post_insert_thread", "pokemon_level");

function pokemon_level()
{
global $db, $mybb;
	$posts = $mybb->user['postnum'];
	$uid = $mybb->user['uid'];
	/* We have their post count, lets calculate their level off of it. */
	if (defined("IN_ADMINCP"))
	{
		$posts=$user['postnum']; $uid = $user['uid'];
	}
	switch ($posts)
	{
	case ($posts==0):
		$level=0; break;
/* more cases are here */
} // Close switch
$update_data['level'] = $level;
}


This is what I found in the datahandler/post.php file
if($forum['usepostcounts'] != 0)
			{
				$update_array['postnum'] = 'postnum+1';
			}
	$db->update_query("users", $update_array, "uid='{$post['uid']}'", 1, true);

So what hook do I use or am I doing something else wrong?
possibly try putting print_r($update_array) in before the $db->update_query() bit, to see if it gets passed Smile
You're not using the hooks correctly.

The function has a variable passed to it that you need to use.
Also you should be using insert_thread_post, not insert_thread.

Check out my DyMy Dice plugin to see how to use these hooks correctly.
Thanks. I managed to get it to work now.