MyBB Community Forums

Full Version: member_do_register_end Hook
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
If I were to log something, upon registration, how would I do that?

I know I need this hook:
member_do_register_end


but it won't work properly.

Help is appreciated,
Thanks. Toungue
Why won't it work properly? Show us what you have.
(2016-01-29, 10:36 PM)nth Wrote: [ -> ]Why won't it work properly? Show us what you have.

As of now, I've nothing. But I need to insert stuff into a table upon registration.
What data do you need? You can use the $mybb->user object.

function register_user()
{
	global $mybb;
	die(var_dump($mybb->user));
}
$plugins->add_hook("member_do_register_end", "register_user");
If it is during user insertion rather than registration, hook at the data-handler. It may cover scenarios where the registration code wouldn't. I.e. creating an user from the ACP.
(2016-01-30, 06:16 AM)Omar G. Wrote: [ -> ]If it is during user insertion rather than registration, hook at the data-handler. It may cover scenarios where the registration code wouldn't. I.e. creating an user from the ACP.

I already have a hook that logs stuff when you login to your account ( datahandler_login_complete_start ) and it works fine. Just need to do it upon registration. I used this for the login part:

function log()
{
	global $db, $loginhandler, $mybb;
        $uid = intval($loginhandler->login_data['uid']);

        // Insert below..
}
datahandler_user_insert_end for user insertion and member_do_register_end for registration.
Issue solved.
(2016-01-30, 09:58 PM)Sazze Wrote: [ -> ]Issue solved.

Could you please post your final results?
Thanks!
(2016-12-22, 10:13 PM)iNilo Wrote: [ -> ]
(2016-01-30, 09:58 PM)Sazze Wrote: [ -> ]Issue solved.

Could you please post your final results?
Thanks!

You'll have to edit some stuff, but here's an example.

* NOTE: Not tried yet, but it should work.
<?php

defined('IN_MYBB') OR die('Nope');

$plugins->add_hook('datahandler_login_complete_start', 'log_login');
$plugins->add_hook('member_do_register_end', 'log_registration');

function log_info()
{
	return [
		'name'             => 'Log',
		'description'   => 'Log some data upon registration and login.',
		'website'         => 'http://community.mybb.com/user-83692.html',
		'author'           => 'Sazze',
		'authorsite'     => 'http://community.mybb.com/user-83692.html',
		'version'           =>  '1.0',
		'compatibility' => '18*'
	];
}

/* Log data when you sign in to an account */
function log_login()
{
   global $db, $loginhandler, $mybb;

   $uid = intval($loginhandler->login_data['uid']);
   
   if (!$uid)
   {
     return;
   }
   
   $insertStuff = array('uid' => $uid);
   $db->insert_query('myTable', $insertStuff);
}

/* Log data upon registration */
function log_registration()
{
   global $mybb, $user_info, $user, $session, $db;

   $newUID = intval($user_info['uid']);
   
   /* Insert new UID */
   $insertStuff = array('uid' => $newUID);
   $db->insert_query('myTable', $insertStuff);
}