In phpBB3 there are four functions you are able to hook into with your custom functions:
phpbb_user_session_handler(); which is called within user::setup after the session and the user object is correctly initialized.
append_sid($url, $params = false, $is_amp = true, $session_id = false); which is called for building urls (appending the session id)
$template->display($handle, $include_once = true); which is called directly before outputting the (not-yet-compiled) template.
exit_handler(); which is called at the very end of phpBB3's execution.
Since i make use of Phpbb3's user system which is closely interconnected with my own custom coding ... I needed a function which deleted a few table entries for that user as well.
The easy and dirty way: Just add the code in the user_delete() function.
Now for a step by step way to create a NEW hook using as little phpbb3 core code changes.
This has been tested with a phpbb3 upgrade ( just merge the files ).
Alter the attached file/function to adapt to your liking for other hooks you want to create !
COPY
hook_user_delete.php TO ./includes/hooks/hook_user_delete.php
(This file will be automatically included because of the hook_ prefix.)
Step2:
Code:
OPEN
./includes/functions_user.php
Code:
FIND
function user_delete
Code:
FIND
$phpEx;
Code:
AFTER, ADD
// ---------------------------------
// hook-my_custom_user_delete START
global $phpbb_hook;
if (!empty($phpbb_hook) && $phpbb_hook->call_hook(__FUNCTION__))
{
if ($phpbb_hook->hook_return(__FUNCTION__))
{
return $phpbb_hook->hook_return_result(__FUNCTION__);
}
}
// hook-my_custom_user_delete END
// ---------------------------------
Step3:
Clear the cache ( ACP > index > clear cache )
OR
FTP to ./cache/ and delete the file data_hooks.php ( you can safely delete this file, it will be automatically re-created )
Now the only thing you have to do is look in the hook_user_delete.php file and adapt the function to your liking.
The core function:
Code:
/**
* Phpbb3 addon ( hook ) to initiate actions when deleting a user from the ACP using the standard user_delete() function
*
* @author Ramon Fincken, RamonFincken.com WebsiteFreelancers.nl
*/
function my_user_delete()
{
global $cache, $config, $db, $user, $auth, $phpbb_hook; // Note: Not sure if you need phpbb_hook, probably not :)
global $phpbb_root_path, $phpEx;
// User to delete: $user_id
$user_id = intval($_POST['u']); // Note: it would be nicer to have this as a param, but this works just fine
if($user_id > 0)
{
// Note: in my case I want to do some deletes, but feel free to
// * call a function ( make sure phpbb has ACCESS to that function ! )
// * do an insert in a "users_deleted" table, which can be read by your own code/CMS to perform actions later :)
$sql = array();
$sql[] = 'DELETE FROM some_table WHERE user_id = '.$user_id;
$sql[] = 'UPDATE LOW_PRIORITY suggestions SET submitter = 0 WHERE submitter = '.$user_id;
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum