MyBB Community Forums

Full Version: newreply_end and newthread_end
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
How could I get the thread from newreply_end and newthread_end, and how can I get the user who replied or made the new thread?
Be clear. You mean grabbing thread id (tid) or what?
Id like to be able to grab the subject of new threads, and pipe it to another application, and the username of the user that posted the thread.

When someone replies I just want to be able to pull their username from the reply and nothing else. I've looked over the docs but I cant find anything besides the hooks
You might have to mess with datahandler hooks, that might be a bit nasty one. Never tried to grab details right after posting a new reply or thread,.

edit: Try to use datahandler hooks and parse $post as reference in your function and for grabbing thread id, use something like:

$post->post_insert_data['tid']

And then you can use get_thread function I think to get thread name and other details from tid.

Not sure, try it.
What do you want to do with such information? I mean, you get the thread/user and then what?
<?php

if(!defined("IN_MYBB"))
{
	die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

$plugins->add_hook('member_activate_emailupdated', 'account_activated_hook');
$plugins->add_hook('member_activate_accountactivated', 'account_activated_hook');
$plugins->add_hook('newthread_do_newthread_end', 'newthread_hook');
$plugins->add_hook('newreply_do_newreply_end', 'newreply_hook');

function account_activated_hook()
{
    global $db, $user;
    
    $query = $db->simple_select("userfields", "*", "ufid=".intval($user['uid']));
    $userfields = $query->fetch_array();
    $field4 = $userfields['fid4'];
//code to send $field4
}


The code above works fine, I get user field 4 for all users, and pass it to my other system.

function newreply_hook()
{
    global $db, $user;
    
    $query = $db->simple_select("userfields", "*", "ufid=".intval($user['uid']));
    $userfields = $query->fetch_array();
    $field4 = $userfields['fid4'];

//send $field4
	
}
function newthread_hook()
{
    global $db, $mybb, $fid, $thread, $user;
	$query = $db->simple_select("userfields", "*", "ufid=".intval($user['uid']));
    $userfields = $query->fetch_array();
    $field4 = $userfields['fid4'];
	$thisuser = $mybb->user['username'];
//code to send $thisuser and $field4
} 
 

The newthread_Hook function I can pass the username fine, but $field4 returns blank and in the newreply_hook function $field4 also returns blank. I can get $field4 properly in the account activated hook but nowhere else.

I'm not worried about parsing the thread subjects anymore, just the information in custom profile field 4. I pipe field4 to an external program that runs some commands based on the information.

Thanks for the help so far.
First off you need to replace:
$query->fetch_array();

With:
$query->fetch_array($query);

Also you need to make $field4 a global:
global $field4;
(2013-03-08, 12:01 AM)Omar G. Wrote: [ -> ]First off you need to replace:
$query->fetch_array();

With:
$query->fetch_array($query);

Also you need to make $field4 a global:
global $field4;

I made the changes, get the same result as before.
Does $field4 is other but null inside the function?
Its not giving me anything at all for $field4. The same code works flawlessly when the user activates the account though. Maybe the profile fields cant be accessed from the reply and new thread hooks?
Pages: 1 2