latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Make username field optional and hide it

Home Forums Community Forum Make username field optional and hide it

This topic contains 1 reply, has 2 voices. Last updated by  Raam Dev 4 years, 10 months ago.

Topic Author Topic
Posted: Friday Mar 9th, 2012 at 5:47 am #7713
Ryan Ghods
Username: ralxz

Hey s2member,

I want to stop using usernames as a login for our WordPress site to make signing up and logging in easier.

I’m looking to:

-Make the username field optional in s2member (skip validation on that form)
-Hide the username field on the signup/paypal pro form
-Have a registration hook to set the username to the persons email upon registration automatically.

I’m not sure exactly where to start. Help would be much appreciated!

List Of Topic Replies

Viewing 1 replies (of 1 total)
Author Replies
Author Replies
Posted: Friday Mar 9th, 2012 at 5:27 pm #7797
Raam Dev
Username: Raam
Staff Member

Hi Ryan,

WordPress requires a username, however you can work around this by dynamically generating a username based on the email address and then hide the Username field (so when the user registers, they will actually get a username — they just won’t know what it is and they won’t see that field).

Then, you can use the WP Email Login plugin to allow your users to login with their email address.

You’ll also need to tweak any emails that go to the user so they don’t mention the username.

Please see this thread from the old forum that explains how I achieved this:

To do something similar on the Pro-Forms during checkout, you can hook into the Pro-Form as follows (this would go in a .php file inside your mu-plugins folder, as described in the aforementioned thread):

add_action ("ws_plugin__s2member_pro_before_sc_paypal_form", "s2_customize_pro_form", 1000);
function s2_customize_pro_form ($vars = array())
	/*  Don't pre populate when/if the Pro Form has just been POSTd, and/or if it's a Modification Form 
		with modify="1", because s2Member already pre populates Pro Forms in that scenario, with the 
		User's existing Email and Username. */
	if(empty ($_POST["s2member_pro_paypal_checkout"]) && empty($vars["attr"]["modify"])) {
        <script type = "text/javascript">
		function getParameterByName(name)
		  name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
		  var regexS = "[\\?&]" + name + "=([^&#]*)";
		  var regex = new RegExp(regexS);
		  var results = regex.exec(window.location.href);
		  if(results == null)
		    return "";
		    return decodeURIComponent(results[1].replace(/\+/g, " "));
            (function ($) /* Wraps this `$ = jQuery` routine. */
                    $.fn.swapWith = function (to) /* Utility extension for jQuery. */
                            return this.each (function ()
                                    var $to = $ (to).clone (true), $from = $ (this).clone (true);
                                    $(to).replaceWith ($from), $ (this).replaceWith ($to);
                    $(document).ready (function () /* Handles email-to-username on keyup. */
						/* Generate random number to append to username, 
                        hopefully making it unique (yes, this isn't perfect!) */
                        var randomNum = Math.ceil(Math.random()*999);

                        if($('input#s2member-pro-paypal-checkout-email').length) {
							var email = 'input#s2member-pro-paypal-checkout-email';
							var login = 'input#s2member-pro-paypal-checkout-username';
						} else {
							var email = 'input#s2member-pro-paypal-registration-email';
							var login = 'input#s2member-pro-paypal-registration-username';

                        /* Fill hidden username field with first part of email address
                            and append randomNum to hopefully make it unique. */
                        $ (email).keyup (function ()
                                $(login).val ($.trim ($ (email).val ().split (/@/)[0].replace (/[^\w]/gi, '')) + randomNum.toString());
                }) (jQuery);
Viewing 1 replies (of 1 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.