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™

Email as Username

Common Questions/Problems/Tips. Posted by Administrators & Support Reps.

Email as Username

Postby bsowards » September 1st, 2011, 10:00 am

Searched the web for a few days on this one, no luck. You guys are awesome, so I figured I'd ask. :)

Is there a recommended way to make the username field for registration accept an email address?

Rather not deal with users trying to guess what username they should pick.

Hooks/function.php works for me as an approach.
User avatar
bsowards
Experienced User
Experienced User
 
Posts: 25
Joined: August 24, 2011

Re: Email as Username

Postby Cristián Lávaque » September 1st, 2011, 10:08 pm

I imagine it should be possible, although I haven't done it myself. Have you searched the hooks related to registration? It won't just be a matter of populating the username with the email field, but also making it validate as a username. Here's a good reference for WP hooks: http://adambrown.info/p/wp_hooks

I hope that helps. :)
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: Email as Username

Postby Jason Caldwell » September 2nd, 2011, 7:28 pm

Thanks for the heads up on this thread Cristián.

@bsowards: I would advise against trying to modify the WordPress core in this regard, because many areas of WordPress, and almost all plugins rely on a strict Username validation and sanitation, which would not expect nor allow characters found in email addresses, such as the @ symbol. This becomes even more of an issue in a Multisite Network installation of WordPress.

Instead, you might try pre-populating the Username field, via JavaScript. Perhaps using jQuery to fill the Username field with only the first part of the email address being typed in ( i.e. johndoe22@example.com ), would automatically populate the Username field with: johndoe22, and then the User would have the ability to change it if they like something better. This would need to be custom coded ( just a few lines ), and then connected via the Hook login_head for the WordPress core.
~ 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: Email as Username

Postby Jason Caldwell » September 2nd, 2011, 8:53 pm

I went ahead and finished this up for anyone that wants to use it.

Create this directory and file:
/wp-content/mu-plugins/email-to-username.php
Code: Select all
<?php
add_action 
("login_head", "s2_email_to_username", 1000);
function s2_email_to_username ()
    {
?>
        <script type = "text/javascript">
            (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. */
                        {
                            var email = 'input#user_email', login = 'input#user_login';
                            $(email).closest ('p').swapWith ($ (login).closest ('p')), $ (email).keyup (function ()
                                {
                                    $(login).val ($.trim ($ (email).val ().split (/@/)[0].replace (/[^\w]/gi, '')));
                                });
                        });
                }) (jQuery);
        </script>
<?php
    
}
?>
* Please make sure there are no extra spaces/tabs/line breaks before or after the <?php ?> tags.
~ 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: Email as Username

Postby bsowards » September 2nd, 2011, 8:58 pm

Thanks Jason, very cool, appreciate the code!
User avatar
bsowards
Experienced User
Experienced User
 
Posts: 25
Joined: August 24, 2011

Re: Email as Username

Postby Cristián Lávaque » September 2nd, 2011, 11:00 pm

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

Re: Email as Username

Postby antseo » September 4th, 2011, 1:54 am

Hi Jason. I built out that dir and page but when I try to sign up as a member, I don't see the username as the email. What am I doing wrong?
User avatar
antseo
Experienced User
Experienced User
 
Posts: 127
Joined: September 2, 2011

Re: Email as Username

Postby bsowards » September 4th, 2011, 9:41 am

This doesn't make the email address the username. Per Jason's earlier comment, that isn't a good idea since so many plugins rely on the username to validate properly - and having an "@" in the username would violate it.

So... this code snippet is for auto-generating usernames instead. As of right now it doesn't appear to validate that the username is available. If we added that then you could have this script auto-generate a username, set username to "display:none," and then use the "Email as Login" plugin.

Effecctively, this would make the email the username as far as the user is concerned, without hacking Wordpress.

I think this will be my next plugin...
User avatar
bsowards
Experienced User
Experienced User
 
Posts: 25
Joined: August 24, 2011

Re: Email as Username

Postby antseo » September 4th, 2011, 10:46 am

Thanks bsowards. so what are the steps then to making that script work using the s2member profile shortcode?
User avatar
antseo
Experienced User
Experienced User
 
Posts: 127
Joined: September 2, 2011

Re: Email as Username

Postby bsowards » September 4th, 2011, 11:12 am

You upload this into wp-content/mu-plugins/s2hacks.php but put it outside the <?php ?> tags.

Once i have this plugin built I'll upload the notification here, probably will take a few weeks.
User avatar
bsowards
Experienced User
Experienced User
 
Posts: 25
Joined: August 24, 2011

Re: Email as Username

Postby antseo » September 4th, 2011, 2:56 pm

I didn't see an attachment. Are you referring to the script above?

So with regard to the username, I guess I don't why the email can't be used since it's a unique identifier?
User avatar
antseo
Experienced User
Experienced User
 
Posts: 127
Joined: September 2, 2011

Re: Email as Username

Postby bsowards » September 6th, 2011, 12:22 pm

Per Jason's comment, wordpress core doesn't allow it.

There's no attachment yet, I haven't made the plugin yet. :)
User avatar
bsowards
Experienced User
Experienced User
 
Posts: 25
Joined: August 24, 2011

Re: Email as Username

Postby antseo » September 6th, 2011, 12:32 pm

okay, no worries. Thanks!
User avatar
antseo
Experienced User
Experienced User
 
Posts: 127
Joined: September 2, 2011

Re: Email as Username

Postby bsowards » September 14th, 2011, 10:40 am

User avatar
bsowards
Experienced User
Experienced User
 
Posts: 25
Joined: August 24, 2011

Re: Email as Username

Postby sonora » October 7th, 2011, 1:51 am

I'm using a plugin in conjunction with s2member Pro to allow users to log in with either their email address OR their username:

http://wordpress.org/extend/plugins/wp-email-login/
User avatar
sonora
Registered User
Registered User
 
Posts: 4
Joined: August 2, 2011

Re: Email as Username

Postby Cristián Lávaque » October 7th, 2011, 3:56 am

Thanks for sharing that! :)
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: Email as Username

Postby antseo » October 8th, 2011, 4:03 pm

nice! thanks!
User avatar
antseo
Experienced User
Experienced User
 
Posts: 127
Joined: September 2, 2011

Re: Email as Username

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

I've modified Jason's 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.

You can see an example and grab my modified version of the script over here: viewtopic.php?f=4&t=15672&p=49082#p49082
Raam Dev || Wherever you are, be there. || Please rate s2Member!
User avatar
Raam Dev
Developer
Developer
 
Posts: 810
Joined: October 26, 2011

Re: Email as Username

Postby antseo » October 28th, 2011, 1:18 pm

okay cool. I did notice when I tried to implement this plugin ... http://wordpress.org/extend/plugins/si- ... wordpress/ ... that the captcha isn't recognized on Submit action. Any idea why that would be?
User avatar
antseo
Experienced User
Experienced User
 
Posts: 127
Joined: September 2, 2011

Re: Email as Username

Postby Jason Caldwell » October 28th, 2011, 2:47 pm

@seozones @bsowards
Forum rank updated 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


Return to Common Questions/Problems/Tips

Who is online

Users browsing this forum: No registered users and 1 guest

cron