• I want to prevent the ability to delete a user on WordPress, and this should affect my admin account too.

    I sometimes mistakenly delete users.

    Thank you.

Viewing 1 replies (of 1 total)
  • You have 2 options for this:

    a) Remove the ability “delete_users” for all roles. With the User Roles plugin you can also do this for admins: https://wordpress.org/plugins/user-role-editor/

    b) Use this code to remove the delete options on the user:

    function custom_remove_user_delete( $actions ) {
    	unset($actions['delete']);
    	return $actions;
    }
    add_filter( 'user_row_actions', 'custom_remove_user_delete', 10, 1);
    add_filter( 'bulk_actions-users', 'custom_remove_user_delete', 10, 1);

    Add it in the functions.php of your child theme, your own plugin or via Code Snippet plugin.

Viewing 1 replies (of 1 total)
  • The topic ‘Prevent user deletion on WordPress’ is closed to new replies.