0

I'm developing a user management table, in which an user (I've already set restriction for for some specific roles) can create/edit or delete a user. How can I delete a user by clicking on delete link or button, I have stored the id in a variable.

  • There'll need to be a request to the server, some code to delete the user, and some checks to verify that the user is capable of doing this. Right now your problem is too large on its own to solve as a single thing, so break it down into sub-problems and tackle each individual part. I suspect the fundamental missing piece you're missing is either AJAX, or how to do stuff only on URL parameters, aka the form handler problem – Tom J Nowell Jul 25 '17 at 19:47
1

If you know the user id, you could create a link similar to https://example.com/wp-admin/users.php?action=delete&user=2 , where the value of the user is the user ID.

You can also hook into a function in the users.php file. It's a core file, so you don't want to change it. But you can use the functions therein to properly delete the user.

|improve this answer|||||
  • This is not working in my case, I'm developing a membership panel, so the head of a group can delete any user under him. I'm able to display the members in a table but can't delete them. Is there any way to call wp_delete_user() on click of anchor tag or button? – Akshat Jul 25 '17 at 19:17
  • 1
    Your template that displays the list of users can have a button (in a form block) that sets a POST variable. Then your template (when the page is submitted) would check the POST variable and call functions based on the POST variable's value. The 'action' of the form(s) on the page would be set to "" (itself). At the top of the template, you'd check for the Submit action of the form, then do something based on that form's POST values. – Rick Hellewell Jul 25 '17 at 19:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.