PriMoThemes — now s2Member® (official notice)

This is now a very OLD forum system. It's in READ-ONLY mode.
All community interaction now occurs at WP Sharks™. See: new forums @ WP Sharks™

User registration without username

s2Member Plugin. A Membership plugin for WordPress®.

User registration without username

Postby Raam Dev » October 26th, 2011, 6:42 pm

Hi All,

I use s2Member primarily for the Paypal -> AWeber integration. I'm creating a subscription-based email offering that requires my readers to subscribe via Paypal to receive premium email content. Once they pay through Paypal, s2Member automatically adds them to my AWeber email list so they receive my premium email content.

I'm trying to make this process as simple as possible for my readers. Since it's an email-based offering, they have no reason to login to my WordPress site. I don't mind the accounts being created for s2Member to handle Subscription Cancellations, etc., however when the registration form is presented to them they're required to enter a "Username", which adds confusion to the process.

I understand that WordPress requires a username to create their account, so I'm wondering if there's any way to automatically generate a username (perhaps based on their email address) and then hide that field on the registration form so that all they see is Email Address, First Name, and Last Name.

Any ideas?
User avatar
Raam Dev
Developer
Developer
 
Posts: 810
Joined: October 26, 2011

Re: User registration without username

Postby Cristián Lávaque » October 27th, 2011, 4:06 pm

I'm afraid I don't know how to do this yet. I know there's a plugin for logging in with the email address, but am not sure if it affects registration too. http://wordpress.org/extend/plugins/wp-email-login/
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: User registration without username

Postby Jason Caldwell » October 27th, 2011, 4:43 pm

Please see this thread. I built a custom hacks file that will accomplish this, and it seems to be working well for others. Goto: viewtopic.php?f=36&t=14806&p=33812#p33812
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: User registration without username

Postby Raam Dev » October 28th, 2011, 1:08 pm

Jason Caldwell wrote:Please see this thread. I built a custom hacks file that will accomplish this, and it seems to be working well for others. Goto: viewtopic.php?f=36&t=14806&p=33812#p33812


Jason, that's brilliant -- thanks!

I've modified your script slightly to hide the username field and append a randomly generated number to the username (to reduce the chances of a user registering with a conflicting username; as noted in the code comments, this isn't a fool-proof solution.) I also hid some other elements that I didn't want to show on the registration page.

Image

For those looking to create a registration form with the username field hidden and the username automatically generated, here you go:

Create this directory and file:
/wp-content/mu-plugins/email-to-username.php
Code: Select all

<?php
add_action 
("login_head", "s2_customize_login", 1000);
function s2_customize_login ()
    {
?>
        <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 "";
          else
            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. */
                        {    
                         /* If this is the register page, customize it */
                         if(getParameterByName('action') == 'register'){
    
                                /* Generate random number to append to username, 
                                hopefully making it unique (yes, this isn't perfect!) */
                                var randomNum = Math.ceil(Math.random()*999);

                                var email = 'input#user_email';
                                var login = 'input#user_login';
                                var firstname = 'input#ws-plugin--s2member-custom-reg-field-first-name';
                                var lastname = 'input#ws-plugin--s2member-custom-reg-field-last-name';
    
                                $('p.message').hide();
                                $('div.ws-plugin--s2member-custom-reg-field-divider-section').hide();
                                $('#reg_passmail').hide();
                                $('#nav').hide();
                                $('#wp-submit').val('Subscribe');
                                $(login).closest ('p').hide();
                                
                                $(email).closest ('p').swapWith ($ (firstname).closest ('p'));
                                $(email).closest ('p').swapWith ($ (lastname).closest ('p'));
                                $(firstname).focus();
                                $(email).attr('tabindex', 50);
                                /* 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);
        </script>
<?php
    
}
?>



(This is based on Jason's version here: viewtopic.php?f=36&t=14806&p=33812#p33812)

Note that I also hid a few other elements on the page. You can delete those lines if you don't want to hide those elements.
Last edited by Raam Dev on January 5th, 2012, 7:12 pm, edited 3 times in total.
Raam Dev || Wherever you are, be there. || Please rate s2Member!
User avatar
Raam Dev
Developer
Developer
 
Posts: 810
Joined: October 26, 2011

Re: User registration without username

Postby Jason Caldwell » October 28th, 2011, 1:15 pm

Nice work! Thanks for sharing this.
~ Updated rank to Experienced User.
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: User registration without username

Postby Cristián Lávaque » October 30th, 2011, 12:46 am

Very cool. :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010


Return to s2Member Plugin

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 2 guests

cron