Wednesday, April 11, 2012

How to delete Joomla users programmatically

You want to delete Joomla users pro-grammatically (in any extensions like component). Leave it dude its easy just get user id & execute delete query on users & user_usergroup_map tables. Thats it. Okay you are right but don't you like to reduce the code? Just pass userid to getInstance & call delete method, that's it. You can see following function i have written for delete joomla 1.7 users.

function deleteuser()
{
$userid = JRequest::getInt('id'); // getting user id from url
$instance = JUser::getInstance($userid);
if($userid)
{
if($instance->delete())
{
return true;
}
}
}

Hope it will help you. However this is working fine for Joomla 1.7 . If you have any other ways you are welcome.