When managing a large scale WordPress membership site, you might find yourself unable to perform certain actions due to the sheer number of users in your database.

One scenario is the user delete process—in which core WordPress allows you to assign the deleted user’s content to another user in the site.

This tutorial includes a simple code recipe to modify the “attribute content” dropdown to only include users with the administrators role. Only including admins ensures that content is reassigned to a user with the appropriate level of access and responsibility, and that your delete user process doesn’t choke on a large user list.

Banner image for Only Include Admins in the WordPress User Delete Dropdown

About the Code Recipe

This code recipe hooks into WordPress’s user management system to apply a filter to the users dropdown displayed when deleting a user.

It checks if the current action is ‘delete’, and if so, modifies the query arguments to list only users with the administrator role in the dropdown. This is achieved through a two-part process:

  • A function to set the query arguments, filtering the list to only include administrators.
  • An action hook to apply this function when the users page is loaded, but only if the current action is ‘delete’.

Once implemented, this change means that only admins will appear in the reassign content dropdown. The code recipe aims to  provide a cleaner, more focused user interface for content reassignment during user deletion.

Screenshot of the menu for deleting users as an admin

The Code Recipe

Adding the Recipe to Your Website

You can add this recipe to your site by creating a custom plugin or using the Code Snippets plugin available for free in the WordPress repository. Read this companion article for step-by-step directions on either method.

Free Course: Membership Site Development—The Basics

Develop a deeper understanding of membership site development in this beginner-level course. Learn how to make your site work better, save yourself time and money, and improve your site's performance.

Featured Image for Membership Site Development Course: The Basics
Was this article helpful?
YesNo