Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.
<?php
/**
* script for bulk user delete operations
*/

require_once('../../config.php');
require_once($CFG->libdir.'/adminlib.php');

$confirm = optional_param('confirm', 0, PARAM_BOOL);

admin_externalpage_setup('userbulk');
require_capability('moodle/user:delete', context_system::instance());

$return = $CFG->wwwroot.'/'.$CFG->admin.'/user/user_bulk.php';

if (empty($SESSION->bulk_users)) {
    redirect($return);
}

> $PAGE->set_primary_active_tab('siteadminnode'); echo $OUTPUT->header(); > $PAGE->set_secondary_active_tab('users'); >
//TODO: add support for large number of users if ($confirm and confirm_sesskey()) { $notifications = ''; list($in, $params) = $DB->get_in_or_equal($SESSION->bulk_users); $rs = $DB->get_recordset_select('user', "deleted = 0 and id $in", $params); foreach ($rs as $user) { if (!is_siteadmin($user) and $USER->id != $user->id and delete_user($user)) { unset($SESSION->bulk_users[$user->id]); } else { $notifications .= $OUTPUT->notification(get_string('deletednot', '', fullname($user, true))); } } $rs->close(); \core\session\manager::gc(); // Remove stale sessions. echo $OUTPUT->box_start('generalbox', 'notice'); if (!empty($notifications)) { echo $notifications; } else { echo $OUTPUT->notification(get_string('changessaved'), 'notifysuccess'); } $continue = new single_button(new moodle_url($return), get_string('continue'), 'post'); echo $OUTPUT->render($continue); echo $OUTPUT->box_end(); } else { list($in, $params) = $DB->get_in_or_equal($SESSION->bulk_users); $userlist = $DB->get_records_select_menu('user', "id $in", $params, 'fullname', 'id,'.$DB->sql_fullname().' AS fullname'); $usernames = implode(', ', $userlist); echo $OUTPUT->heading(get_string('confirmation', 'admin')); $formcontinue = new single_button(new moodle_url('user_bulk_delete.php', array('confirm' => 1)), get_string('yes')); $formcancel = new single_button(new moodle_url('user_bulk.php'), get_string('no'), 'get'); echo $OUTPUT->confirm(get_string('deletecheckfull', '', $usernames), $formcontinue, $formcancel); } echo $OUTPUT->footer();