How to ban user accounts in WordPress

To ban user accounts in WordPress using the functions.php file, you can use the wp_ban_user() function. This function is part of the WordPress core and can be used to ban a user by their user ID or login name.

Here is an example of how you can use the wp_ban_user() function to ban a user by their user ID:

// Ban user accounts in WordPress
// More snippets at wpunplugged.com 

wp_ban_user( $user_id );

In this example, $user_id is the ID of the user you want to ban.

You can also ban a user by their login name using the following code:

// Ban user accounts in WordPress
// More snippets at wpunplugged.com 

wp_ban_user( $user_login );

In this example, $user_login is the login name of the user you want to ban.

It’s important to note that banning a user will prevent them from logging into your site, but it will not delete their user account. To delete a user account, you will need to use the wp_delete_user() function.

Share this post

You might also like...

Sucuri for WordPress Review
Plugins

Sucuri for WordPress Review

Sucuri for WordPress is a powerful security plugin that helps protect your website from hackers and malicious software. It provides a comprehensive website security solution,

Read More »

Comment

Your email address will not be published. Required fields are marked *