WordPress filter hook · part of WordPress core

pre_user_login

A WordPress core filter that 14 plugins also fire themselves, running on 198K+ sites between them.

“Filters the username before being validated.”

How to use pre_user_login

It's a filter: your callback receives the value, and must return the (changed) value. Add this to your theme's functions.php or a small custom plugin:

functions.php
add_filter( 'pre_user_login', function( $user_login ) {
	// Change $user_login here.
	return $user_login;
}, 10, 1 );

Argument names come from LTI Tool's source. Other plugins may pass different values: check the call in the plugin you're targeting below.

This hook is fired by WordPress core too. Official reference on developer.wordpress.org →

14 plugins that fire pre_user_login

Sorted by active installs. Each entry shows where the plugin calls the hook and what it passes.

  1. Advanced Custom Fields: Extended icon Advanced Custom Fields: Extended100,000+ installs apply_filters( 'pre_user_login', $action['save']['user_login'] ) includes/modules/form/module-form-action-user.php:223
  2. BuddyPress icon BuddyPress90,000+ installs apply_filters( 'pre_user_login', $user_name ) bp-members/bp-members-functions.php:1705
  3. FeedWordPress icon FeedWordPress8,000+ installs apply_filters( 'pre_user_login', sanitize_user( $newuser_name ) ) admin-ui.php:431
  4. Court Reservation icon Court Reservation80+ installs apply_filters( 'pre_user_login', sanitize_user( wp_unslash( $_REQUEST['user_login'] ), true ) ) admin/partials/courtres-user.php:190
  5. Import Members from CSV for Paid Memberships Pro icon Import Members from CSV for Paid Memberships Pro80+ installs apply_filters( 'pre_user_login', $sanitized_user_login ) src/modules/Users/class-import-user.php:368
  6. LTI Tool icon LTI Tool50+ installs apply_filters( 'pre_user_login', $user_login ) includes/SyncEnrolments.php:84
  7. Create User With Password Multisite icon Create User With Password Multisite40+ installs apply_filters( 'pre_user_login', sanitize_user(wp_unslash($_REQUEST['user_login']), true) ) php/cuwp.php:116
  8. PHPBB Single Sign On icon PHPBB Single Sign On10+ installs apply_filters( 'pre_user_login', $user_login ) module.wp.php:15
  9. SPR Posts Import icon SPR Posts Import10+ installs apply_filters( 'pre_user_login', $auth->creator->__toString() ) app/models/main_model.php:84
  10. KickPress icon KickPress10+ installs apply_filters( 'pre_user_login', sanitize_user( stripslashes( $user_login ), true ) ) kickpress-api.php:1989
  11. PopForms Lite icon PopForms Lite10+ installs apply_filters( 'pre_user_login', sanitize_user( $user_name ) ) inc/pop-functions.php:121
  12. Add user 2 in 1 icon Add user 2 in 1Fewer than 10 installs apply_filters( 'pre_user_login', sanitize_user( wp_unslash( $_REQUEST['user_login'] ), true ) ) add-form.php:156
  13. Lil’Omi Avatars icon Lil’Omi AvatarsFewer than 10 installs apply_filters( 'pre_user_login', $trim_user_login ) _process_user.php:22
  14. vXor Convertor icon vXor ConvertorFewer than 10 installs apply_filters( 'pre_user_login', $user_login ) lib/convert.func.php:412

Need a customisation built on this hook?

Tell us what you want to change and which plugin it's for. We'll write it, test it and send it back as a small plugin.