Page 1 of 1

Edit Username Field

PostPosted: December 30th, 2011, 9:05 pm
by mcmcmc
Hello,

I don't want users to have aliases or usernames as such, I want their username to be their full name. Is there a way of either changing the 'Username' to 'Full Name' or removing the username field and having Full Name as a required field that is processed as the username?

Thanks!

Re: Edit Username Field

PostPosted: January 2nd, 2012, 5:47 pm
by Raam Dev
WordPress requires that all usernames be unique, so you may run into trouble using the Full Name as the username.

I recently configured s2Member to hide the username field on the registration form. However, the username field is still there (as WordPress requires a username), it's just hidden.

When the user types in their email address, JavaScript automatically updates the contents of the hidden username field with the first part of the user's email address (everything before the @ symbol).

It also appends some random numbers to the end of the username to ensure that it's unique. (You can read all about how to get this working here: viewtopic.php?f=4&t=15672&p=48910#p49082)

I then have the WP Email Login plugin installed, which allows my users to login with their email address (so they never need to know their username).

Do you think that would work for you?

Re: Edit Username Field

PostPosted: January 4th, 2012, 3:03 pm
by mcmcmc
You sir - are a legend!

That is excellent - been searching for too long trying to find a solution. This seems to be it.

Thank you so much!

Re: Edit Username Field

PostPosted: January 4th, 2012, 6:07 pm
by Raam Dev
You're most welcome! Glad I could help. :)

Re: Edit Username Field

PostPosted: January 4th, 2012, 6:11 pm
by mcmcmc
Am I missing something? I copied the php file and put it into the /wp-content/mu-plugins but when I look at the register page username still shows?

Thanks! :)

Re: Edit Username Field

PostPosted: January 4th, 2012, 6:13 pm
by Raam Dev
Can you copy and paste the contents of the PHP file you used here (please use [code] boxes). Also, if you could provide us with a link to your registration page, that would help diagnose the problem. :)

Re: Edit Username Field

PostPosted: January 4th, 2012, 8:32 pm
by mcmcmc
Here you go!

Also getting errors on the page, http://themagicpeople.org/test/wp-login ... n=register

Thanks!

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. */
                        {
                            /* Generate random number to append to username,
                            hopefully making it unique (yes, this isn't perfect!) */
                            var randomNum = Math.ceil(Math.random()*999999);
                           
                            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';
                           
                            /* Hide stuff we don't want to show on the registration form */
                            $('p.message').hide();
                            $('div.ws-plugin--s2member-custom-reg-field-divider-section').hide();
                            $('#reg_passmail').hide();
                            $('#nav').hide();
                            /* $(login).closest ('p').hide(); */
                            $('#wp-submit').val('Subscribe'); /* Change 'Register' button to 'Subscribe' */
                           
                            /* 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
    }
?>

Re: Edit Username Field

PostPosted: January 5th, 2012, 7:14 pm
by Raam Dev
I updated the code on this page: viewtopic.php?f=4&t=15672&p=49082#p49082

Could you update what's in your PHP file and try it again?

Re: Edit Username Field

PostPosted: January 6th, 2012, 12:53 pm
by mcmcmc
I think that's done the trick! Thank you! Now to get it all set up :)

Re: Edit Username Field

PostPosted: January 7th, 2012, 7:05 pm
by Raam Dev
Awesome! Let us know if you have any other questions. :)