Prevent deleting own account if currently login

Hello everyone I’m using phprad classic and I would like to ask on how to prevent deleting own account if an admin currently login and have access on page list account.

Example: admin2 currently login and then have access in page list of accounts next is if I delete my own account which admin2. Restrict it or don’t allow to delete because I’m currently login.

Thank you :blush:

For a Classic project, the following code should do the trick. The following code should be added to the user table in Page EventsBeforeDelete.

$arr_id = explode(",", $rec_id);

if(in_array(auth()->user()->fieldname, $arr_id)) {
    return $this->redirect($redirectUrl, "You cannot delete your account.");
}

Please note that in the code, you must replace “fieldname” with your user table ID field name.

1 Like

Thank You for very fast response❤️