There is no way to do this with only one query. But to be honest – deleting user takes more than one query itself…
You shouldn’t use custom SQL for that, because there are many things you could break this way… Always use WP functions, if they exists (what if some plugin logs every deleted user, or what if some other action is needed, etc.)
You can use get_user_by
to achieve that. Here’s the example:
$user = get_user_by( 'login', 'john' );
if ( $user ) { // get_user_by can return false, if no such user exists
wp_delete_user( $user->ID );
}
The fields you can get user by are: ID
| slug
| email
| login
.
Related Posts:
- Adding fields to the “Add New User” screen in the dashboard
- How to check if a user exists by a given id
- Use author author display name in permalink structure for pages and posts
- Get a list of all available fields in the User Profile
- Logout redirect to current page – function
- How to paginate the get_users function?
- How to display random users with avatars
- How to manually activate user in dashboard only by admin
- Add new user : make the fields First Name and Last name required
- Change labels on ‘Nickname’ and ‘Biographical Info’ in user-edit.php
- Order get_users() by last login date. Is it possible?
- How can I tell when a user is logged in?
- how to get and display logged in user’s recently read posts
- Displaying a random user with a shortcode
- How to update BuddyPress xprofile fields programmatically? [closed]
- How to detect first visit of a user?
- Can I pass two roles to the function get_users?
- How can I add an image field to BuddyPress Extended Profile Fields? [closed]
- Create dropdown of users in admin dashboard
- password protected post policy
- Remove the deleted users avatar from list
- Get Current User info using wp_localize_script, in functions.php
- How to add custom fields to my custom registration form
- create shortcode to list users with specific meta key value
- Don’t delete a page if it holds users
- How to make custom column Admin>Users sortable?
- Execute a ultimate member action when user role is updated
- Filter out other users comments. Visualize only own comments and editor role users’ comments
- Force to use STRONG users password and implement rule to prevent REUSE [closed]
- Change label for registration Fields
- Condition OR for current user ID
- How to Use Global Variables Inside Header and Footer
- Secondary Menu and Logged In Users
- Why get_user_by() doesn’t work in my code?
- Filter to wp_list_authors
- How to add array [closed]
- Add Link to Users List (Backend) to open each users front-end profile
- Suggest Users basing on User taxonomy
- Showing user profile data on front-end
- Modify function to only return values for the user that’s logged in
- loginout function customization
- User meta and public function security
- call wp_insert_user in custom class doesnt work
- Get users with different roles and call function on each of them (user_meta)
- Show errormessages on wrong username/password on custom loginform?
- How can I show different content for different user-levels?
- Custom user role still showing up after deletion, ideas?
- referencing the current user in a page i created in wordpress
- Show metadata in users.php – wordpress
- Deleting guests profile users after 1.5 hours
- wp_get_current_user return ID = 0 when used outside of wordpress, such as webhook / fulfillment dialogflow
- Allow user only create specific tags
- Add Change role button for list of user in an event
- get_current_user_id() always return 0 in if else statement
- Show users last read posts for each user?
- How to add number to wordpress count function?
- get USER ID in functions.php using user_register action
- Whats the proper way to add a new user via a front end form?
- sort by date in users
- Is it ok to use a function to output the text domain name in a wordpress theme
- Issue with wp_get_attachment_image() and SVG file type
- deregister scripts on certain page
- Override parent theme function that is not hooked or in the functions.php file
- function to include is_home, is_archive, is_category, is_author etc in one function?
- How to remove canonical url in wordpress? add_filter( ‘wpseo_canonical’, ‘__return_false’ ); not Working for me
- get_the_excerpt() not returning anything when post has no excerpt
- Why isn’t is_page_template() adding a body class?
- Query children and parent title
- Creating loop within functions.php
- Limit filter upgrader_post_install to a single plugin
- How to test for Super Admin
- creating shortcode to pull json array
- Pass Shortcode Attribute to footer Script
- Variable if post is sticky in functions.php
- Remove the product category module block from the Woocommerce product page
- How to get correct URLs in network wide menu (Multisite)?
- Remove category from url
- ‘Attempt to modify property of non-object’ warning
- Conditional functions.php on page template
- Optimizing a WordPress site
- different style sheet for just one page template
- Problem with comments_number()
- How to target post and pages and not all post types in admin?
- Dequeue script to prevent javascript event conflict on wordpress child theme
- Upgraded server now class My_Walker_Nav_Menu extends Walker_Nav_Menu not working
- How to include any template using Shortcode fuction?
- display a div on ervery site but not frontpage?
- Replace header image on all other pages but home – URL issue
- Getting images from media library and get_the_date() not working
- Using add_image_size in functions.php to get original uploaded file
- How do I change where “You must be logged in to comment” directs users?
- Login cookies blocked after customizing hashing method
- Enable CORS Request for hostname using IP address
- Change default color scheme in twentyfifteen child theme?
- Restrict access if logged out except for homepage
- DISABLE wordpress upgrade page
- Moving CDN jQuery to footer does not work?
- Register a widget area when a theme option has been saved?
- Blank child theme – functions.php problem
- Hiding Google Analytics code based on theme options