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.

login redirection

Home Forums Community Forum login redirection

This topic contains 9 replies, has 3 voices. Last updated by  Cristián Lávaque 4 years, 5 months ago.

Topic Author Topic
Posted: Saturday Jul 14th, 2012 at 4:31 pm #19263

I have resources that are login protected. When a user clicks a link to a resource post when not logged in, it takes them to the Membership page. I have placed the default wp login form on this page (with a custom user registration form via Gravity Forms User Registration add-on), but when I log in, it redirects me to the same page (where I see my profile form). I realize that the redirect is a function of the login form code but I was wondering how I might change the redirect link in the login form code to show the resource post after logging in.
If that is not something I can do, how can I set it up so that just the content of the page is protected? Perhaps when you click the resource post link, it can take you to the post page with the content hidden and a login form is displayed and either a registration form or a link to the membership page (where I can place my registration form). Then when the user logs in, the current page redirect will show them the resource post page with the content revealed.

Check out the demo site here: http://www.envisiondemo.com/acumen
Resources, specifically, are at: http://www.envisiondemo.com/acumen/resources/

List Of Topic Replies

Viewing 9 replies - 1 through 9 (of 9 total)
Author Replies
Author Replies
Posted: Sunday Jul 15th, 2012 at 7:26 am #19296

Hi Stephanie.

Your login form has this hidden field:

[hilite pre_code]

[/hilite]

This is what’s causing the redirection you experienced. You can change that URL to the one for the resource that sent him to the Membership Options page. If you look at the URL of the Membership Options page, you’ll notice a lot of variables, including the page the user was redirected from. [hilite path]Dashboard -› s2Member® -› API / Scripting -› Membership Options Page Variables (MOP Vars)[/hilite]

So try using those variables to update your login redirection dynamically.

I hope that helps. :)

Posted: Sunday Jul 15th, 2012 at 9:58 pm #19319

Thanks for the fast reply.
I see the documentation that you pointed out, but I’m not entirely sure how to apply it to my situation. Any chance you could be more specific on how to use the data string from the membership area page?

I know that my redirect is pointing to the current page, but I am not sure how to change the url to then redirect to the previous page.

Please help. Thanks.
-Steph

Posted: Tuesday Jul 17th, 2012 at 4:30 am #19450
Raam Dev
Username: Raam
Staff Member

Hi Steph,

The first thing you’ll need to do is install and activate the Exec-PHP Plugin. Once you’ve done that, you can add the code below to your Membership Options Page.

<?php $_g = stripslashes_deep ($_GET); ?>
<?php if (isset ($_g&#91;"_s2member_seeking"&#93;&#91;"post"&#93;)) { $redirect_id = esc_html($_g&#91;"_s2member_seeking"&#93;&#91;"post"&#93;); } ?>
<?php if (isset ($_g&#91;"_s2member_seeking"&#93;&#91;"page"&#93;)) { $redirect_id = esc_html($_g&#91;"_s2member_seeking"&#93;&#91;"page"&#93;); } ?>
<?php if (!$redirect_link = get_permalink( $redirect_id )) { $redirect_link = "http://www.envisiondemo.com/acumen/membership-area/"; } ?>

<input name="redirect_to" value="<?php echo $redirect_link; ?>" type="hidden">

Note how I’ve modified the <input> line that contains the hidden redirect_to value. After you add the PHP code above the login form code, you’ll need to modify that <input> line as shown above (you should find it in your login form code).

Posted: Tuesday Jul 17th, 2012 at 11:32 am #19526

I added the ExecPHP plugin to my site.

I tried implementing the code above and I get this error in a lovely white page when I try to save the post:

Method Not Implemented
POST to /acumen/wp-admin/post.php not supported.

I tried just adding lines 1-4 to the post (not doing anything to the form yet, just adding php), and I still get the same error.

Any ideas?

Posted: Wednesday Jul 18th, 2012 at 4:30 am #19588
Raam Dev
Username: Raam
Staff Member

Hi Stephanie,

I’m not sure. There could be an error in the PHP code somewhere on that page.

If you’re not comfortable with PHP, I recommend posting your job on jobs.wordpress.net. Diagnosing custom code like this is outside the scope of our support policy.

Posted: Wednesday Jul 25th, 2012 at 2:11 pm #20220

The 501 error is being created by your code specifically, not my custom php:

<?php $_g = stripslashes_deep ($_GET); ?>
<?php if (isset ($_g["_s2member_seeking"]["post"])) { $redirect_id = esc_html($_g["_s2member_seeking"]["post"]); } ?>
<?php if (isset ($_g["_s2member_seeking"]["page"])) { $redirect_id = esc_html($_g["_s2member_seeking"]["page"]); } ?>
<?php if (!$redirect_link = get_permalink( $redirect_id )) { $redirect_link = "http://www.envisiondemo.com/acumen/membership-area/"; } ?>

I do not have any errors in my code. The site otherwise works fine.

Your code is:
1. stripping slashes from $_GET array — the url string — this is this line that is creating the 501 error
2. evaluating if there is an ID value for _s2member_seeking a post, and saving that ID to $redirect_id
3. evaluating if there is an ID value for _s2member_seeking a page, and saving that ID to $redirect_id
4. If there is not permalink for $redirect_id, assign the redirect link to the membership-area page

Then use the $redirect_link variable in my login form code. This all makes sense.

I disabled the visual editor and have been able to execute other php code through the admin so I know that’s not the issue.

Ultimately, I had to pull all of the content of the page into a template because it didn’t seem that you could use stripslashes_deep ($_GET); through the admin. I tried just placing the code to get the $redirect_link variable into the template and then using the variable in the login code in the editor, but for some reason they won’t communicate.

So just FYI, your code does not work as intended.

I solved my problem, but I find it rather irritating that you don’t support what seems to be basic functionality of a PAID plugin. Thanks for your help thus far.

Posted: Wednesday Jul 25th, 2012 at 6:13 pm #20233

Stephanie, did you try doing something like this with the MOP vars for the [hilite mono]redirect_to[/hilite] field of your login form?

[hilite pre_code]
'; ?>
[/hilite]
Posted: Thursday Jul 26th, 2012 at 1:42 pm #20323

No I have not tried that, but since the solution that I came up with works, I’m leaving it as is.

Thanks.

Posted: Thursday Jul 26th, 2012 at 9:38 pm #20351

That’s cool. What matters is that it’s working. :)

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