Install
This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.
Install straight from GitHub with WP-CLI:
wp plugin install https://github.com/kvn1234/alley-code-example-random-username-generator/archive/refs/heads/main.zipA dependency-free WordPress MU-plugin with over 100 entertaining adjectives and nouns. Suggestions look like Befuddled_Quokka_0042 or Cantankerous_Waffle_7310.
Install
-
Extract the ZIP.
-
Create
wp-content/mu-pluginsif necessary. -
Put delightfully-random-usernames.php directly in that directory:
wp-content/mu-plugins/delightfully-random-usernames.php
WordPress loads it automatically; no activation is needed. It appears under Plugins → Must-Use. The README need not be uploaded. WordPress does not automatically load PHP files inside MU-plugin subdirectories: if you use a subdirectory, provide a separate loader PHP file directly in mu-plugins. Do not use the ordinary plugin ZIP installer. Remove the PHP file to uninstall; no settings or database records are stored.
Requires WordPress 6.0+ and PHP 7.4+; use currently supported WordPress/PHP releases on production sites.
Behavior
On a fresh GET of Users → Add New User (wp-admin/user-new.php), a small inline script fills only the empty Username field in the create-user form. It runs once in the page footer. Existing values, server-rendered defaults, focused fields, and disabled/read-only fields are left alone. Every POST redisplay is skipped, including validation errors and intentionally empty submissions. The suggested value remains fully editable; clearing it does not trigger regeneration.
The plugin never creates or updates accounts, filters pre_user_login, changes submitted data, or touches existing users. WordPress processes whatever username the administrator submits. No AJAX endpoints, external requests, dependencies, options, or scheduled tasks are added. Without JavaScript, or if suggestion generation fails, the normal manual-entry form remains available.
Multisite: backend suggestions are disabled by default because core Multisite signup validation rejects underscores. Network Admin is always excluded. The generator remains callable, but its documented format is not compatible with default Multisite signup rules. Do not enable suggestions on Multisite unless your integration explicitly supports that format.
All random choices use random_int(), including a suffix from 0000 through 9999. Candidates are strictly sanitized with sanitize_user(), checked for format, length, validity and reserved usernames, then checked with username_exists(). Collisions trigger retries, up to 100 attempts. Suggestions are not reservations: another account could claim the name before submission; WordPress performs its normal final checks. The administrator's replacement is subject to WordPress validation, not this plugin's suggestion format.
Reuse and filters
Call after WordPress loads, preferably on init or later:
$suggestion = \DelightfullyRandomUsernames\generate_username( 'registration' );
if ( ! is_wp_error( $suggestion ) ) {
// Your front-end integration can use esc_attr( $suggestion ) in an input.
// Preserve submitted values and handle registration validation separately.
}
Returns a string or WP_Error (dru_empty_vocabulary, dru_random_failure, or dru_exhausted). The generator has no capability restriction so a future front-end integration can reuse it; the integration owns permissions, nonce checks, rate limits, and account creation. Nothing is automatically enabled on the front end.
| Filter | Arguments | Purpose |
|---|---|---|
dru_adjectives |
array $words, string $context | Replace or extend adjectives. |
dru_nouns |
array $words, string $context | Replace or extend nouns. |
dru_generated_username |
string $candidate, string $context, int $attempt | Customize each candidate before sanitization and all checks. |
dru_admin_enabled |
bool $enabled, WP_Screen $screen | Disable backend suggestions; defaults to false on Multisite. |
dru_admin_capability |
string $capability | Require an additional capability; defaults to create_users. Core create_users is always required. |
The backend context is admin; direct calls default to default. Word-list entries must be strings of 1–25 ASCII letters; invalid entries and duplicates are removed. The final filtered suggestion must still match Letters_Letters_####, be no longer than 60 bytes, and pass WordPress checks. A constant colliding or invalid candidate eventually returns WP_Error. The core illegal_user_logins and validate_username filters are respected.
Put customization code in another MU-plugin or site plugin (register filters before the generator runs):
add_filter( 'dru_adjectives', function ( $words, $context ) {
$words[] = 'Bamboozled';
return $words;
}, 10, 2 );
// Optional: restrict suggestions to administrators with manage_options.
add_filter( 'dru_admin_capability', function () {
return 'manage_options';
} );
// Alternatively, turn off backend suggestions while retaining the generator:
// add_filter( 'dru_admin_enabled', '__return_false' );
Error strings use the delightfully-random-usernames text domain. Word lists are intentionally stable English identifiers; customize them with filters. For local translations, load your translation catalog on init using WordPress's load_muplugin_textdomain() with that domain and your catalog directory relative to mu-plugins. No translation catalogs are bundled. Inline scripts use wp_print_inline_script_tag(), allowing WordPress's script-attribute filters to integrate with a site's Content Security Policy.
Verification
PHP syntax checked on PHP 8.5.7. Focused tests with WordPress API stubs and a JavaScript DOM stub passed for zero padding, filtered collisions, bounded retries, invalid filters, reserved names, entropy failures, screen/capability restrictions, POST preservation, existing values, focused fields, and editability. Not tested against a running WordPress installation or every supported PHP version.
After installation, open Add New User, replace the suggestion, submit with an invalid email, and verify the chosen username survives the error. Check that user-edit and front-end registration remain unaffected.
Reference: WordPress Add New User source, username_exists, and inline script output.