Page 1 of 1

Redirect Profile page based on role

PostPosted: December 29th, 2011, 3:58 pm
by guyu2
I have a setup where I want to redirect free subscribers away from the Wordpress Profile page, but not paid members. Can this be done with the short code something like this:

[s2Member-Profile role="subscriber"/]

If not is there another way?

Appreciate the help.

8-) Guy

Re: Redirect Profile page based on role

PostPosted: December 29th, 2011, 4:27 pm
by Eduan
Check this video by the Lead Developer and please tell me if it helps:
http://www.s2member.com/paypal-modifica ... ons-video/

Hope this helps. :)

Re: Redirect Profile page based on role

PostPosted: December 29th, 2011, 4:32 pm
by Raam Dev
Hi Guy,

So you want regular paying subscribers to see a profile page after logging in, but the free subscribers to go somewhere else?

To send all users to the Profile Page after logging in, you'll want to select the Profile Page as the Login Welcome Page in WP Admin -> s2Member -> General Options -> Login Welcome Page.

Then the most simple way to redirect free subscribers is to use Advanced/PHP Conditionals (WP Admin -> s2Member -> API/Scripting -> Advanced/PHP Conditionals) to check if the user viewing the Profile Page is a free subscriber (s2member_level0). If they are a free subscriber, then the HTML Meta Refresh redirects them to another page.

Code: Select all
<?php if (current_user_is("s2member_level0")) { ?>
<meta http-equiv="refresh" content="0; url=http://example.com/free-subscribers-area">
<?php } ?>


You'll need to install and activate the PHP Execution plugin before adding this code to the top of your Profile Page (i.e., wherever you're using the [s2Member-Profile /] shortcode.

The downside to this method is that the free subscriber will probably see the contents of the Profile Page for a brief moment before being redirected away.

If you want to get more advanced, you can use a Custom Page Template for your Profile Page and then add the PHP code directly to that page template, preventing the [s2Member-Profile /] shortcode from ever loading for free subscribers.

Re: Redirect Profile page based on role

PostPosted: December 29th, 2011, 8:45 pm
by guyu2
Hi,

Thanks to both Eduan and Raam Dev.

I tried both your suggestions and ran into several issues I could not resolve - with my very limited knowledge.

Did find a solution that works by adding a function to my functions.php file as follows:
Code: Select all
function subscriber_redirect(){
  if( is_admin() && !defined('DOING_AJAX') && ( current_user_can('subscriber') ) ){
    wp_redirect('http://mydomain.com/?page_id=xxxx');
    exit;
  }
}
add_action('init','subscriber_redirect');


Ps: Eduan, I think that the video you pointed me to is going to prove very useful in future. Appreciate it. :D

Re: Redirect Profile page based on role

PostPosted: December 29th, 2011, 9:40 pm
by Eduan
OK, glad I could help in something. :)

Anything else you need just ask.

Re: Redirect Profile page based on role

PostPosted: December 30th, 2011, 3:47 pm
by Raam Dev
Glad to help! Let us know if you have any other questions. :)