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™

Front End Registration and Login

s2Member Plugin. A Membership plugin for WordPress®.

Front End Registration and Login

Postby Henry » July 25th, 2010, 3:46 am

How can I create a front-end registration and login page for s2Member instead of using wp-login.php

I know I could use .htaccess to mask wp-login.php but, I want to protect my backend and I want to have the registration and login process to be a part of my website so the transition is seamless. Is there a way to do this using WP/s2Member hook and filters?
Henry
Guest User
Guest User
 

Re: Front End Registration and Login

Postby Jason Caldwell » July 28th, 2010, 7:06 am

Hi Henry. Thanks for the great question.

Here are two ways to accomplish this:

1. You can build a form into your theme, or into a specific Post or Page that you've created. Have that form submit all the same fields to: /wp-login.php?action=register ( this would give you additional control over the cosmetics ).

2. You can upgrade to s2Member Pro. The s2Member Pro Module makes it possible for s2Member to use PayPal® Pro Forms ( instead of standard PayPal® Buttons ). PayPal® Pro Forms integrate seamlessly with WordPress® Shortcodes. This allows you to keep Customers on your site at all times, and it consolidates the Checkout / Registration steps into a single form that you can dress up just the way you like.

The s2Member Pro Module, also includes a Shortcode for each type of Form, even for free registrations, where no payment is required, for Level #0 access.

but, I want to protect my backend

Just to point out. The wp-login.php file is not part of the WordPress backend.
I realize that it is primarily intended for admin access ( by default, without s2Member ), but the /wp-login.php file resides outside the /wp-admin/ directory. So it IS safe to use that.
~ 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: Front End Registration and Login

Postby Henry » July 31st, 2010, 2:41 am

Jason,

My goal is to have members stay on my site without having to view the WP dashboard so they don't have to go to wp-login.php, I want a seamless transition from registration to editing their user profile, having them stay on the front-end of the site to register and manage their account.

What hooks should I use to create such a form? Where would I find them?

Can I integrate your existing Edit User profile page without using an iframe?
Henry
Guest User
Guest User
 

Custom Registration Page - a problem

Postby martonic » August 3rd, 2010, 1:51 pm

Jason Caldwell wrote:Hi Henry. Thanks for the great question.

Here are two ways to accomplish this:

1. You can build a form into your theme, or into a specific Post or Page that you've created. Have that form submit all the same fields to: /wp-login.php?action=register ( this would give you additional control over the cosmetics ).


Hi Jason,

You can do this, but then the Login Page still has a "Register" link at the bottom, which leads to the "usual" registration page. :(

Is there a good way to get rid of that - or better, make it point to my Custom Registration Page? :?:
User avatar
martonic
Experienced User
Experienced User
 
Posts: 70
Joined: July 14, 2010

Re: Front End Registration and Login

Postby Jason Caldwell » August 5th, 2010, 1:46 pm

Thanks for the great question.
or better, make it point to my Custom Registration Page?

Yes. Inside the functions.php file for your WordPress theme, you can add these lines:
Code: Select all
<?php
add_action("init", "redirect_registrations"); function redirect_registrations()
    {
        if(preg_match("/wp-login\.php/", $_SERVER["REQUEST_URI"])
           && $_GET["action"] === "register")
            { header("Location: [YOUR CUSTOM URL HERE]"); exit(); }
    }
?>

Change the part that says: [YOUR CUSTOM URL HERE]
~ 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: Front End Registration and Login

Postby martonic » August 10th, 2010, 12:11 pm

Ah so - thanks! :mrgreen:
User avatar
martonic
Experienced User
Experienced User
 
Posts: 70
Joined: July 14, 2010

Re: Front End Registration and Login

Postby Henry » August 12th, 2010, 2:14 am

You could extend it to include: login, lostpassword too, correct?

Code: Select all
<?php
add_action("init", "redirect_registrations"); function redirect_registrations()
    {
        if(preg_match("/wp-login\.php/", $_SERVER["REQUEST_URI"])
           && $_GET["action"] === "register")
            { header("Location: [YOUR CUSTOM URL HERE]"); exit(); }
    }
add_action("init", "redirect_lostpassword"); function redirect_lostpassword()
    {
        if(preg_match("/wp-login\.php/", $_SERVER["REQUEST_URI"])
           && $_GET["action"] === "lostpassword")
            { header("Location: [YOUR CUSTOM URL HERE]"); exit(); }
    }
?>
Henry
Guest User
Guest User
 

Re: Front End Registration and Login

Postby Jason Caldwell » August 18th, 2010, 1:15 am

Absolutely. Thanks for that additional post.
~ 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: Front End Registration and Login

Postby martonic » August 23rd, 2010, 3:36 pm

Jason Caldwell wrote:Thanks for the great question.
or better, make it point to my Custom Registration Page?

Yes. Inside the functions.php file for your WordPress theme, you can add these lines:
Code: Select all
<?php
add_action("init", "redirect_registrations"); function redirect_registrations()
    {
        if(preg_match("/wp-login\.php/", $_SERVER["REQUEST_URI"])
           && $_GET["action"] === "register")
            { header("Location: [YOUR CUSTOM URL HERE]"); exit(); }
    }
?>

Change the part that says: [YOUR CUSTOM URL HERE]


(EDITED)

Hi again Jason,

I did this, but the "custom registration page" does not work at all.

When submitted, it just resets the form to all blanks - and reloads the page. :(

It did work, until I added the "redirection code" above. Although that DOES make the registration link redirect - it also makes the custom registration page fall down. :(

Any suggestions? :?:
User avatar
martonic
Experienced User
Experienced User
 
Posts: 70
Joined: July 14, 2010

Re: Front End Registration and Login

Postby martonic » August 23rd, 2010, 5:00 pm

SOLVED

Here is the code you need for the hook:

Code: Select all
add_action("init", "redirect_registrations");
function redirect_registrations() {
    if(preg_match("/wp-login\.php/", $_SERVER["REQUEST_URI"])
       && $_GET["action"] === "register" && $_GET["register"] !== "1")
    { header("Location: /bg-register.php"); exit(); }


Note the addition of:

Code: Select all
&& $_GET["register"] !== "1"


This additional test is needed because the same file and the same action are used both to present the registration form, and to process it!

Then, in your custom registration form, use this action:

Code: Select all
action="/wp-login.php?action=register&register=1"


You also need the following in your custom registration code, inside the form itself:

Code: Select all
<?php
    echo '<input type="hidden" name="ws_plugin__s2member_registration" value="' . esc_attr (wp_create_nonce ("ws-plugin--s2member-registration")) . '" />' . "\n";
?>


To have the function wp_create_nonce() available, you need to include pluggable.php.

Finally, you also need to supply your own Javascript form validation.

Whew!
User avatar
martonic
Experienced User
Experienced User
 
Posts: 70
Joined: July 14, 2010

Re: Front End Registration and Login

Postby martonic » August 24th, 2010, 6:57 pm

The "custom registration page" is harder than I thought.

Even after all the above, when you put in a name that is already in use, or a bad email, the function still redirects to the "usual" log-in page with the error messages attached. :o

Drat!
User avatar
martonic
Experienced User
Experienced User
 
Posts: 70
Joined: July 14, 2010

Re: Front End Registration and Login

Postby Jason Caldwell » August 29th, 2010, 11:45 pm

If you can't get that working "exactly like you want", you may want to consider using these functions to accomplish a truly "100% custom" registration system, while still maintaining compatiblity with s2Member.

You can use these functions for that:
Code: Select all
$id = wp_create_user(login, pass, email)
wp_new_user_notification($id, pass)

Check the WordPress® Codex for further details.
OR, you can have a look at paypal-checkout.inc.php
in the s2Member Pro distribution for actual examples.

In short, the `wp_create_user()` function will fire the "user_register" Hook in WordPress®, which triggers s2Member as well. So if you POST data to a custom processing routine that receives form input, and calls `wp_create_user()`, you've got a truly custom integration.
~ 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: Front End Registration and Login

Postby martonic » August 30th, 2010, 12:41 am

Hi Jason,

Thank you very much. I wound up using a custom page that posts to itself, thus removing WP from the equation completely - creating a password, entering the user in the database, including the s2Member fields, and sending their email "by hand". At least it provides full control over all the details - although, as you imply, it might not work correctly down the road if "things change".
User avatar
martonic
Experienced User
Experienced User
 
Posts: 70
Joined: July 14, 2010

Re: Front End Registration and Login

Postby Jason Caldwell » August 30th, 2010, 1:44 pm

martonic wrote:Hi Jason,

Thank you very much. I wound up using a custom page that posts to itself, thus removing WP from the equation completely - creating a password, entering the user in the database, including the s2Member fields, and sending their email "by hand". At least it provides full control over all the details - although, as you imply, it might not work correctly down the road if "things change".

That works too. Glad to hear you got it working.
~ 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 s2Member Plugin

Who is online

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

cron