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™

Edit Username Field

s2Member Plugin. A Membership plugin for WordPress®.

Edit Username Field

Postby mcmcmc » December 30th, 2011, 9:05 pm

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!
User avatar
mcmcmc
Registered User
Registered User
 
Posts: 5
Joined: December 30, 2011

Re: Edit Username Field

Postby Raam Dev » January 2nd, 2012, 5:47 pm

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?
Raam Dev || Wherever you are, be there. || Please rate s2Member!
User avatar
Raam Dev
Developer
Developer
 
Posts: 810
Joined: October 26, 2011

Re: Edit Username Field

Postby mcmcmc » January 4th, 2012, 3:03 pm

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!
User avatar
mcmcmc
Registered User
Registered User
 
Posts: 5
Joined: December 30, 2011

Re: Edit Username Field

Postby Raam Dev » January 4th, 2012, 6:07 pm

You're most welcome! Glad I could help. :)
Raam Dev || Wherever you are, be there. || Please rate s2Member!
User avatar
Raam Dev
Developer
Developer
 
Posts: 810
Joined: October 26, 2011

Re: Edit Username Field

Postby mcmcmc » January 4th, 2012, 6:11 pm

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! :)
User avatar
mcmcmc
Registered User
Registered User
 
Posts: 5
Joined: December 30, 2011

Re: Edit Username Field

Postby Raam Dev » January 4th, 2012, 6:13 pm

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. :)
Raam Dev || Wherever you are, be there. || Please rate s2Member!
User avatar
Raam Dev
Developer
Developer
 
Posts: 810
Joined: October 26, 2011

Re: Edit Username Field

Postby mcmcmc » January 4th, 2012, 8:32 pm

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
    }
?>
User avatar
mcmcmc
Registered User
Registered User
 
Posts: 5
Joined: December 30, 2011

Re: Edit Username Field

Postby Raam Dev » January 5th, 2012, 7:14 pm

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?
Raam Dev || Wherever you are, be there. || Please rate s2Member!
User avatar
Raam Dev
Developer
Developer
 
Posts: 810
Joined: October 26, 2011

Re: Edit Username Field

Postby mcmcmc » January 6th, 2012, 12:53 pm

I think that's done the trick! Thank you! Now to get it all set up :)
User avatar
mcmcmc
Registered User
Registered User
 
Posts: 5
Joined: December 30, 2011

Re: Edit Username Field

Postby Raam Dev » January 7th, 2012, 7:05 pm

Awesome! Let us know if you have any other questions. :)
Raam Dev || Wherever you are, be there. || Please rate s2Member!
User avatar
Raam Dev
Developer
Developer
 
Posts: 810
Joined: October 26, 2011


Return to s2Member Plugin

Who is online

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

cron