2011-11-16, 01:44 PM
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.
This is what I found in the datahandler/post.php file
So what hook do I use or am I doing something else wrong?
$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?