[HOW-TO] Remove a huge array of users

Code-talk. Anything related to the Studio, extension developing and phpBB coding.


Post Reply
User avatar
3Di
Founder
Founder
Posts: 1705
Joined: 12 Mar 2018 20:10
Location: Milan (IT) Frankfurt (DE)
Contact:

[HOW-TO] Remove a huge array of users

Post by 3Di »

Create a PHP executable file and put it in the root of your board then execute it

<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
include($phpbb_root_path . 'includes/functions_user.' . $phpEx);

// Array of user IDs - example [4,5,6,9,12,100]
$user_ids = [];

foreach ($user_ids as $user_id)
{
	/**
	 * Delete user(s) and their related data
	 *
	 * @param string	$mode			Mode of posts deletion (retain|remove)
	 * @param mixed		$user_ids		Either an array of integers or an integer
	 * @param bool		$retain_username	True if username should be retained, false otherwise
	 * @return bool
	 */

	// Note: the whole function is done within a SQL transaction so it is safe!
	user_delete('remove', $user_id, false)
}

echo 'Done!';

🇪🇺 Honour and respect to all the Healthcare Heroes. 🇮🇹


Post Reply