MyBB Community Forums

Full Version: Call a script when a user registers
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

So I have a website that uses mybb's users to login/etc, the problem I am facing is that i want it so that whenever someone subscribes a new row in one of my personnal tables gets created, and when someone deletes his account his row in my personnal table gets deleted, this is because I want to add a few more infos to the user besides the one for mybb, I don't want to use MySQL trigger for this, so any ideas ?
I have no idea what your post means but judging by your title, you want to hook into the register page.

$plugins->run_hooks("member_do_register_end");
I tried to use what you suggested, but I'm getting this error:
( ! ) Fatal error: Cannot pass parameter 2 by reference in C:\folder\site_synchronization.php on line 9

this is my code

<?php
if(!defined("IN_MYBB"))
{
     die("Not Allowed.");
}

// Hooks

$plugins->run_hooks("member_do_register_end", "site_synchronization_add_site_user"); 

// end of Hooks

function site_synchronization_info() {
     return array(
        "name"  => "site_synchronization",
        "description"=> "allows mybb users to be the same as the website's.",
        "website"        => "http://site.com/",
        "author"        => "Jirachier",
        "authorsite"    => "http://site.com/",
        "version"        => "1.0",
        "guid"             => "",
        "compatibility" => "*"
    ); 
}

function site_synchronization_activate() {
     global $db;
	 
	 $site_synchronization_group = array(
	     'gid'=>'NULL',
		 'name'=>'site_synchronization',
		 'title'=>'site synchronization',
		 'description'=>'Settings for site synchronization',
		 'disporder'=>"1",
		 'isdefault'=>'no',
	 );
	 $db->insert_query('settinggroups', $site_synchronization_group);
     $gid = $db->insert_id();

     $site_synchronization_setting = array(
        'sid'=>'NULL',
        'name'=>'enabled_site_synchronization',
        'title'=>'Do you want site_synchronization Enabled',
        'description'=>'If Yes People Can Use site_synchronization, If No People Cannot Use site_synchronization.',
        'optionscode'=>'yesno',
        'value'=>'1',
        'disporder'=>1,
        'gid'=>intval($gid),
     );
	 
	 $query = $db->simple_select("users", "uid");
	 $mybb_users_ids = array();
	 while($user = $db->fetch_array($query))
	 {
	     $mybb_users_ids[] = $user['uid'];
	 }
	 $query = $db->query("SELECT site_users.user_id FROM site_users");
	 $site_users_ids = array();
	 while($user = $db->fetch_array($query))
	 {
	     $site_users_ids[] = $user['user_id'];
	 }
	 $users_ids = array_unique($mybb_users_ids, $site_users_ids);
	 
	 foreach($users_ids as $user_id)
	 {
	     $db->query("INSERT INTO site_users(user_id, auth_level) VALUES(".$user_id.", 0)");
	 }
}

function site_synchronization_deactivate() {
     global $db;
     $db->query("DELETE FROM ".TABLE_PREFIX."settings WHERE name IN ('enabled_enabled_site_synchronization')");
     $db->query("DELETE FROM ".TABLE_PREFIX."settinggroups WHERE name='site_synchronization'");
     rebuild_settings();
	 $db->query("DELETE FROM site_users");
}

function site_synchronization_add_site_user() {
     global $db, $user_info;
	 
	 $db->query("INSERT INTO site_users(user_id, auth_level) VALUES(".$user_info['uid'].", 0)");
}

function site_synchronization_delete_site_user() {
     global $db, $user_info;
	 
	 $db->query("DELETE FROM site_users WHERE site_users.user_id=".$user_info['uid']);
}


?>
You want to register a hook for member_do_register_end, not run the hook in site_synchronization.php.

$plugins->add_hook("member_do_register_end", "site_synchronization_add_site_user");

http://docs.mybb.com/Plugins-The_Hook_System.html
Oh thanks ! It's working now, there is only one issue, if a someone registers to the forums the site_synchronization_add_site_user function does get called but if a user is created from the Admin CPanel it doesn't get called, I tried to find a hook for it but I couldn't.
There is a list of hooks used by MyBB.