[updated] Stuck while programming a plugin
#1
Hi Guys,
at the moment I am working on a plugin that connects to a external database and updates it when a user posts in a thread or creates a new thread.

This is my first plugin, so I have some questions and it would be really great if you could help me with this questions.

I try to get the username with the $user_data variable, but I cant get it to work. This is how I tried it:
//taken from the email admin on new email plugin
function storeconnecter_global_start() {
    global $mybb, $user_info, $db;

    if ($mybb->settings['storeconnecter_enable'] == 1) {
        // query user information
        $query = $db->simple_select(
            "users",
            "uid, username, email, regip, regdate, referrer",
            "uid=" . (int)$user_info['uid'] . ""
        );
        $userInfo = $db->fetch_array($query);
        
        echo "My first plugin works! Username: ".$userInfo['username'];
        
    }
}
and this is what I have got: http://d.pr/i/5S3V
Can you please tell me what I have done wrong.

If i would like to trigger a function when a new reply is made, are this two hook-points correctly ? newthread_end, newreply_end

Thanks alot for your help
Reply
#2
Instead of $user_info use $mybb->user
So get rid of the $user_info global
And replace $user_info['uid'] with $mybb->user['uid]
Basically $mybb->user is the same as $userInfo after the query, which you can remove.

So your code can be:
//taken from the email admin on new email plugin
function storeconnecter_global_start() {
    global $mybb;

    if ($mybb->settings['storeconnecter_enable'] == 1) {
        
        echo "My first plugin works! Username: ".$mybb->user['username'];
        
    }
}
Reply
#3
Thanks for the info, if I have a custom row (for example a steamid row) can I access this row with
$mybb->user['steamid'] ?
Or do I need to use the query I have got in the code ?
Reply
#4
If it's in the users table, it's in the $mybb->user array Smile
Reply
#5
Thanks alot for your answer.

I have got another question:
How can I access the data that is entered in a userfield ? (mybb_userfields)
It would be great if you could help me with this question too
Reply
#6
(2013-02-27, 09:02 PM)Euan T. Wrote: If it's in the users table, it's in the $mybb->user array Smile

It really is awesome if you don't know that and someone tells you. Big Grin
[retired]
Reply
#7
(2013-02-27, 09:04 PM)Arrow768 Wrote: Thanks alot for your answer.

I have got another question:
How can I access the data that is entered in a userfield ? (mybb_userfields)
It would be great if you could help me with this question too

For that, you'll need to query the DB I'm afraid.
Reply
#8
If you know the ID number of the Custom Profile Field that you can access it without a query like this:

$GLOBALS["mybb"]->user['fid5']

replace 5 with the ID # of your Custom Profile Field (find the ID by hovering in ACP)
[retired]
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)