If “Anyone can register” is on under Settings → General, a single-site WordPress install accepts usernames that multisite would reject: spaces, dots, @ signs, mixed case and whole phrases up to 60 characters. Spammers use that room to put a domain name or a short pitch into the username, which then lands in the “New user registration” emails sent to the admin.
Matt Mullenweg brought this up on November 8 in Conservative in What We Accept, writing that the conservative username approach “doesn’t apply to registrations when you’re not in multisite mode.” He suggested stricter rules for new registrations and asked whether comment notification emails should drop the comment content.
As of 2026-11-16 that is a proposal, not a change in core. You do not have to wait for it. A few filters give your single site the multisite rules today.
The rules multisite already enforces
Multisite checks new usernames in wpmu_validate_user_signup(). Single sites only run the looser sanitize_user(). The multisite rules are:
- only lowercase letters (a-z) and numbers
- at least 4 characters and at most 60
- not only numbers
- not on the blocked list (
illegal_namesplus theillegal_user_loginsfilter)
Those four rules alone throw out every username with a space, a dot or a domain in it. That is what the code below copies.
Step 1. Create a must-use plugin
I put this kind of code in a must-use plugin rather than the theme’s functions.php. It keeps working after a theme switch, and nobody can deactivate it by accident from the Plugins screen.
Create the folder wp-content/mu-plugins/ if it does not exist, then add a file named wpxss-strict-usernames.php. WordPress loads every PHP file in that folder automatically. Take a copy of the site files first if you are working on production.
Step 2. Apply the multisite rules to new registrations
Paste this into the new file:
<?php
/**
* Plugin Name: WPXSS Strict Usernames
* Description: Multisite-style username rules for single-site registration.
*/
function wpxss_username_problem( $login ) {
if ( preg_match( '/[^a-z0-9]/', $login ) ) {
return 'Usernames can only contain lowercase letters (a-z) and numbers.';
}
if ( strlen( $login ) < 4 ) {
return 'Username must be at least 4 characters.';
}
if ( strlen( $login ) > 60 ) {
return 'Username may not be longer than 60 characters.';
}
if ( preg_match( '/^[0-9]*$/', $login ) ) {
return 'Sorry, usernames must have letters too!';
}
return '';
}
add_filter( 'registration_errors', function ( $errors, $sanitized_user_login, $user_email ) {
$problem = wpxss_username_problem( $sanitized_user_login );
if ( $problem ) {
$errors->add( 'wpxss_username', '<strong>Error:</strong> ' . $problem );
}
return $errors;
}, 10, 3 );
add_filter( 'illegal_user_logins', function ( $logins ) {
return array_merge( $logins, array( 'admin', 'administrator', 'root', 'webmaster', 'support' ) );
} );
Open wp-login.php?action=register in a private window and try a username like John Smith. Registration should stop with the lowercase error, while johnsmith goes through.
The registration_errors filter must always return $errors. Any error inside it aborts the registration, so the account is never created and no email goes out.
The messages are copied from the multisite source, so visitors see the same wording a network would show them. If you want to allow capital letters, change the first pattern to /[^a-zA-Z0-9]/.
💡 This only touches the public registration form. Users you create under Users → Add New or with wp user create do not run registration_errors, so your own workflows keep working.
Step 3. Cover WooCommerce My Account registration
WooCommerce creates customers in wc_create_new_customer(), which has its own filter, woocommerce_registration_errors, with the same three arguments. Add this to the same file:
add_filter( 'woocommerce_registration_errors', function ( $errors, $username, $email ) {
if ( '' === $username ) {
return $errors;
}
$problem = wpxss_username_problem( $username );
if ( $problem ) {
$errors->add( 'wpxss_username', $problem );
}
return $errors;
}, 10, 3 );
The empty check is there for stores that let WooCommerce build the username from the email address. In that setup the customer never types a username, so there is nothing to validate.
Step 4. Take the comment text out of notification emails
The second half of the proposal is about comment emails. By default, the “new comment” and “please moderate” emails include the full comment, links and all. A short email with just the post title and a link to the comment gives spammers nothing to show off in your inbox.
function wpxss_short_comment_email( $message, $comment_id ) {
$comment = get_comment( $comment_id );
if ( ! $comment ) {
return $message;
}
return sprintf(
"New comment on \"%s\".\n\nReview it here: %s\n",
wp_strip_all_tags( get_the_title( $comment->comment_post_ID ) ),
admin_url( 'comment.php?action=editcomment&c=' . $comment->comment_ID )
);
}
add_filter( 'comment_notification_text', 'wpxss_short_comment_email', 10, 2 );
add_filter( 'comment_moderation_text', 'wpxss_short_comment_email', 10, 2 );
comment_notification_text controls the email for approved comments and comment_moderation_text the one for comments waiting in the queue. Remove either line if you want to keep the full text in that email. If good comments keep ending up in spam, this post on finding what flags them helps.
Clean up the junk accounts that already got in
The filters only stop new registrations. To find existing accounts that break the new rules, back up the database first, then list subscribers whose username would fail:
wp db export before-user-cleanup.sql
wp user list --role=subscriber --fields=ID,user_login,user_email,user_registered
wp user list --role=subscriber --field=user_login | grep -vE '^[a-z0-9]{4,60}$'
The last command prints only the usernames that fail the character and length rules. Read them before you delete anything, because real customers who registered years ago may be in there too.
Delete the junk by ID. If an account wrote posts, add --reassign with the ID of the user who should keep them, or the posts are deleted with the account:
wp user delete 123 124 125 --reassign=1
The same reassign job in the admin and in SQL is covered in Assign all posts from one user to another.
The cheapest prevention is turning registration off if you do not need it. Plenty of sites still have “Anyone can register” ticked from an old membership plugin. wp option update users_can_register 0 switches it off. WooCommerce has its own account creation settings, separate from this one.
TL;DR: Single-site WordPress takes almost any username, and spammers fill that space. Drop the mu-plugin above into wp-content/mu-plugins/ to apply the multisite rules (a-z and 0-9, 4 to 60 characters, not only numbers, plus a blocked list) to the registration form and WooCommerce, strip the comment text from notification emails, and clean out the accounts that already got through with WP-CLI.

