• Skip to primary navigation
  • Skip to main content

RocketGeek

Home of WP-Members, The Original WordPress Membership Plugin

  • WordPress Plugins
    • WP-Members
      • FAQs
      • Quick Start
      • Documentation
      • Extensions
    • Advanced Options
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Download Protect
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Invite Codes
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • MailChimp Integration
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • PayPal Subscriptions
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Salesforce Web-to-Lead
    • Security
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Text Editor
      • Purchase the Plugin
      • Get the Pro Bundle
    • User List
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • User Tracking
      • Documentation
      • Purchase the Plugin
      • Get the Pro Bundle
    • Memberships for WooCommerce
    • WordPass
  • Blog
    • Basics
    • Tips and Tricks
    • Filters
    • Actions
    • Code Snippets
    • Shortcodes
    • Design
    • Release Announcements
  • Store
    • Cart
    • Checkout
  • Contact
  • Log In
  • Show Search
Hide Search
Home » Tips and Tricks » Remove username from registration

Remove username from registration

Chad Butler · Mar 27, 2025 ·

This article is provided free. Find out how you can get full access to premium content, including how-to articles and support forums, as well as priority email support and member exclusive plugin extensions..

 

There is often the question of using an email for a username. In WordPress, there is never a good reason to do this because the core WP schema does not allow for it. This post covers why you should work within the existing schema, how you can do that, and provides simple code snippets you can use to customize the WP-Members login and registration forms to handle it.

There are three fields required to create a user, two of which must be unique:

  • user_login (unique)
  • user_email (unique)
  • user_pass (a password)

Without all three of these, you cannot create a new user using WP’s functions. There may be third-party applications (such as plugins) that work around this, but anything that is not done within this schema is asking for trouble at some point.

What about simply inserting an email into the user_login field?

Not a good idea. WP does not allow for this field to be changed. Sure, you can do it directly in the DB with an update query, but what if you have a third party app that causes a problem with that? Also, what about privacy issues with displaying emails. When you display the username in another application like a forum, you’ll be exposing the user’s email address – sometimes to their disdain.

No, it’s best to work within the schema provided and not try to bend it to your will in ways that it was not intended.

So can you remove the username field in WP-Members?

Yes, you can. You will need to filter it out of the form. AND, you will need to insert a filler value into the field before the user is inserted because this field is required to create a user. But it’s not difficult, and since it’s not difficult, then you are better off doing that instead of working outside the scope of the application.

The following code snippet will handle it:

/**
 * Removes the username field from the 
 * WP-Members registration form using
 * the `wpmem_fields` filter.
 */
add_filter( 'wpmem_fields', function( $fields, $tag ) {
    if ( 'register' == $tag ) {
        unset( $fields['username'] );
    }
    return $fields;
}, 10, 2 );

/**
 * Inserts a filler value for the username
 * field using the user's email address so
 * that the user can be inserted.
 * 
 * Uses the `wpmem_pre_validate_form` filter
 * and `wpmem_create_username_from_email()
 */
add_filter( 'wpmem_pre_validate_form', function( $post_data, $tag ) {
    if ( 'register' == $tag ) {
        $post_data['username'] = wpmem_create_username_from_email( $post_data['user_email'] );
    }
    return $post_data;
}, 10, 2 );

/**
 * This filters the text for the main body
 * login form and the widget to only display
 * "Email" instead of "Username or email".
 */
add_filter( 'wpmem_default_text', function( $text ) {
    $text['login_username'] = 'Email';
    $text['widget_login_username'] = 'Email';
    return $text;
});

What’s happening in these code snippets?

The first one is a filter for the registration form, which is used for registration, but also for user profile update. If it’s the new registration process, the filter removes the username field.

The second filter uses the wpmem_pre_validate_form filter so that prior to the form fields being validated to make sure everything is OK before insertion, it puts a value into the username field. Noting that we want this to be seamless for the user, and we need a unique value, it uses wpmem_create_username_from_email() to generate a value for us. This is a function in the WP-Members API that will generate a value from the user’s email address (everything before the “@” symbol), check to make sure that is a unique value (that it doesn’t already exist in the db), and it will rerun until the generated value is unique. It’s important to point out, the user doesn’t need to see this value nor know about it. They don’t need it to log in. They can log in with their email address.

The last filter removes mention of username from the login form so that it just says “Email” for the input field.

Tips and Tricks wpmem_create_username_from_email, wpmem_pre_validate_form

Ready to get started?

Join Today!

© 2025 · butlerblog.com · RocketGeek is built using WordPress, WP-Members, and the Genesis Framework

  • butlerblog.com
  • WP-Members Support Subscription
  • Terms of Service
  • Privacy Policy
  • Refund Policy