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.

User registration without username

Home Forums Community Forum User registration without username

This topic contains 6 replies, has 3 voices. Last updated by  Raam Dev 4 years, 1 month ago.

Topic Author Topic
Posted: Thursday Nov 8th, 2012 at 4:57 pm #31060

Hey guys, I am such a huge fan of s2memeber! We have used it on a number of projects and it never fails to impress me!

Anyway, I need to get the following working on our current project.

http://www.primothemes.com/forums/viewtopic.php?f=4&t=15672&p=49082#p49082

I’ve implemented everything and its not working, im taking a stab at saying its because im not using the same form. The form I need it to work on is authnet-checkout-form.php

Your help would be much appreciated!

List Of Topic Replies

Viewing 6 replies - 1 through 6 (of 6 total)
Author Replies
Author Replies
Posted: Thursday Nov 8th, 2012 at 6:26 pm #31080

Arrgg Im slipping down the list, Raam I know your out there ;) and its you that wrote the above article on how to do this :)

Im a little confused with where to put the file is /wp-content/mu-plugins/email-to-username.php in all situations? is mu something to do with Multisite, because im not using that…IM not sure if its because I have the wrong form or my file is in the wrong place :(

Posted: Friday Nov 9th, 2012 at 3:53 am #31104

Hi Mike.

Raam I know your out there ;) and its you that wrote the above article on how to do this :)

I’ll wait for him to help you with this one. I don’t know JavaScript, so I can’t do much about it.

is mu something to do with Multisite

No, it stands for “must use”. http://codex.wordpress.org/Must_Use_Plugins

Hey guys, I am such a huge fan of s2memeber! We have used it on a number of projects and it never fails to impress me!

Thank you for the kudos! :)

Posted: Friday Nov 9th, 2012 at 12:17 pm #31144
Raam Dev
Username: Raam
Staff Member

Hi Mike,

Yes, you are correct that it’s not working because you’re using the Authorize.net forms. The code in that original post is for customizing the default WordPress registration page (you can tell because it hooks into the login_head action).

However, since writing that post, I’ve also customized this hack to work on a PayPal Pro-Form on my website; you can see that code below:

<?php
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&#91;"s2member_pro_paypal_checkout"&#93;) && empty($vars&#91;"attr"&#93;&#91;"modify"&#93;)) {
?>
        <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. */
                        {	
								
						/* 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';
							//$('#s2member-pro-paypal-checkout-form-username-div').hide();
						} else {
							var email = 'input#s2member-pro-paypal-registration-email';
							var login = 'input#s2member-pro-paypal-registration-username';
							//$('#s2member-pro-paypal-registration-form-username-div').hide();
						}
						
						

                        /* 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
		}
    }
?>

You’ll notice that the main difference is at the top, where you can see the action being hooked into (ws_plugin__s2member_pro_before_sc_paypal_form). That causes this code to run on the PayPal Pro-Forms for membership levels (Dashboard -› s2Member® -› PayPal® Pro Forms -› Membership Level # Forms).

You will need to locate the correct hook for the Authorize.net form that you’re using (probably ws_plugin__s2member_pro_before_sc_authnet_form) and change that in the hack.

You’ll also need to do “view source” when displaying your Authorize.net Pro-Form on a page and locate the correct names of the email and username fields (e.g., input#s2member-pro-paypal-checkout-email should be changed to whatever it’s called on the Authorize.net Pro-Form) and then update those names in the hack.

Finally, you’ll notice that I commented out the following on lines 44 and 48:

//$('#s2member-pro-paypal-registration-form-username-div').hide();

That code hides the Username section. I recommend leaving those lines commented out so that you can see if the username is actually being automatically generated when you type in the email address. Then, once you’re sure that it’s being generated, you can hide that section by uncommenting those lines (remove the leading //).

This code should go in a PHP file in your wp-content/mu-plugins/ folder. If that folder doesn’t exist, you should create it. You can call the PHP file anything, but I recommend naming it s2hacks.php. Any PHP files in that directory will automatically be loaded every time you load a WordPress post/page.

The mu-plugins directory holds Must Use Plugins. These plugins are activated and run automatically with WordPress and do not require manual activation.
Posted: Friday Nov 9th, 2012 at 12:23 pm #31148

Thanks a million for the reply!

Ill work on it now and give any feedback!

Posted: Friday Nov 9th, 2012 at 6:26 pm #31179

WHOHOO….Worked like a charm!

Thanks a million!!

Posted: Monday Nov 12th, 2012 at 4:53 pm #31350
Raam Dev
Username: Raam
Staff Member

Woohoo! Glad to hear it, Mike! :)

Viewing 6 replies - 1 through 6 (of 6 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.