Page 3 of 4

Re: Conditional redirect to another page

PostPosted: August 13th, 2011, 10:02 pm
by Bruce C
No, your viewable content can be put underneath that.

Here's the shortcode equivalent:
Code: Select all
[s2If current_user_can(access_s2member_ccap_basic) && !current_user_can(administrator) ]
<script type="text/javascript">window.location = 'http://scrapbookcampus.com/basic-tutorials-for-scrapbooking-with-paintshop-pro/';</script>
[/s2If]
[s2If !current_user_can(access_s2member_ccap_basic)]
[/s2If]


This code will:

Redirect if you can access ccap_basic, and are not an admin.
The empty section underneath is just a placeholder, essentially.

Re: Conditional redirect to another page

PostPosted: August 13th, 2011, 10:11 pm
by cassel
Just double and triple checking. In the first part of the code you use (access_s2member_level1) and in the second you use (access_s2member_ccap_basic). Shouldn' t they be identical?

Re: Conditional redirect to another page

PostPosted: August 13th, 2011, 10:13 pm
by Bruce C
Yea, sorry I was editing that my browser got locked.

Re: Conditional redirect to another page

PostPosted: August 13th, 2011, 10:27 pm
by cassel
YAYYYY! It works and i even tried it on the live page, and it works PERFECTLY!!!
Maybe this little snippet could be saved and posted somewhere on this forum or wherever for others to use!

Thanks for your help and your patience.

Re: Conditional redirect to another page

PostPosted: August 13th, 2011, 10:32 pm
by Bruce C
I'm VERY glad it works for you now. Sorry it took so long to come up with, and your patience with me, I'm not so used to using the shortcodes yet.

:D

Re: Conditional redirect to another page

PostPosted: August 13th, 2011, 10:49 pm
by cassel
Could you just help me with this one now? I might be getting too brave, but now i have this scenario:

If you try to access PageA and have access to more, then you are sent to PageB (that is the code you gave me and works)
If you try to access PageB (reserved for higher access) and do NOT have that access, i want you to go to PageA

I know that s2Member will redirect the person without proper access to a membership option page, but if i can redirect them to the sales page for that particular "course" it would be easier and more logical. So i used your code and inverted the conditions like this:
Code: Select all

[s2If !current_user_can(access_s2member_ccaps_basic) ]<script type="text/javascript">window.location = 'http://scrapbookcampus.com/register-basic-scrap-course-with-psp/';</script>[/s2If]
[s2If current_user_can(access_s2member_ccap_basic) && !current_user_can(administrator) ][/s2If]


But i am getting a Parse error something. Did i make a mistake in the editing of the code? Maybe a syntax error?

Re: Conditional redirect to another page

PostPosted: August 13th, 2011, 10:58 pm
by Bruce C
Try this on a test page:

Code: Select all
[s2If !current_user_can(access_s2member_ccaps_basic) && !current_user_can(administrator)]
<script type="text/javascript"> window.location = 'http://scrapbookcampus.com/register-basic-scrap-course-with-psp/';</script>
[/s2If]
[s2If current_user_can(access_s2member_ccap_basic)]
[/s2If]


It should work.

Re: Conditional redirect to another page

PostPosted: August 13th, 2011, 11:01 pm
by cassel
Still getting the parse error.

Re: Conditional redirect to another page

PostPosted: August 13th, 2011, 11:04 pm
by Bruce C
Try this:

Code: Select all
[s2If !current_user_can(access_s2member_ccap_basic)]
<script type="text/javascript"> window.location = 'http://scrapbookcampus.com/register-basic-scrap-course-with-psp/';</script>
[/s2If]
[s2If current_user_can(access_s2member_ccap_basic)]
[/s2If]


Otherwise, I don't know what the problem could be.

Re: Conditional redirect to another page

PostPosted: August 13th, 2011, 11:08 pm
by cassel
No luck :(
BUT.... this time i was using the code inside a leaf and not inside a PAGE in WP. Maybe that is the problem. I will do more tests tomorrow and i will get back to you!

Re: Conditional redirect to another page

PostPosted: August 14th, 2011, 10:35 am
by cassel
Ok it seems to work when i put the code on the WP page instead of the Headway leaf. So that is ok. Now, i just noticed something and i wonder if i messed up somewhere else: if i start on the main page (http://scrapbookcampus.com) and i am logged in as an authorized member (Member1/Member1), and i clilck on the Basic Scrap Course box or the Basic Scrap in the navigation, i will get redirected, but it seems to be caught in a loop of redirecting all the time.

I just used the code up there, as is, i removed all the permission limitation (level and ccaps) so that only the redirect would be in effect. What did i do wrong?

EDIT: let me know when you come back and want to check that page so i can reset it like this. For now, i will put it back in a way that i know will leave access to the students.

Re: Conditional redirect to another page

PostPosted: August 14th, 2011, 10:53 am
by Bruce C
Okay, so I logged into your test account, and it seems to be working for me, at least for the sale pitch page.
Are you saying you get a never-ending loop whenever you put the code on the non-sales-pitch page?

Re: Conditional redirect to another page

PostPosted: August 14th, 2011, 11:03 am
by cassel
Hold on... i had removed the redirect. I'll put it back and tell you.

Re: Conditional redirect to another page

PostPosted: August 14th, 2011, 11:03 am
by Bruce C
Alright.

Re: Conditional redirect to another page

PostPosted: August 14th, 2011, 11:09 am
by cassel
Gremlins at work now. OK it works for the redirect now (not sure why it was looping earlier), however, now, if you are logged out and click on the Basic Scrap in the navigation menu it will START loading the "course" page, and then redirect to the "sales" page. Strangely, it does not do that the other way around. Humm...

Do you see that?

Also, at the very bottom of that page, i see some coding displayed so maybe i forgot something in the syntax or something like that.

Re: Conditional redirect to another page

PostPosted: August 14th, 2011, 11:36 am
by Bruce C
It starts loading the page because you are using the JavaScript redirect code. It's just a side-effect since it's in the body of the page, and not the head.

It looks like that placeholder code is either duplicated, or not needed. Those shortcodes can do weird things sometimes (lol)

Re: Conditional redirect to another page

PostPosted: August 14th, 2011, 11:46 am
by cassel
Any idea why it does that side-effect in that direction but not in the other direction? If you are logged in and click on the middle box (which should send you to the sale pitch page) it will redirect you immediately to the course list, without that "flickering".

Then, for the placeholder, any suggestion on how to avoid it?

Do you think using the other code that had the <head> in it would work better?

For the php edit, how would that impact other redirects i might want to use? I think it works out great to redirect the visitor to the matching sales page! Maybe something to integrate easier in the s2Member in future versions.

Re: Conditional redirect to another page

PostPosted: August 14th, 2011, 12:04 pm
by Bruce C
The PHP redirect is generally faster.

However, in order to use it, you cannot use shortcode equivalents.
Code: Select all
<?php
if (!current_user_can('access_s2member_ccap_basic') && !current_user_can('administrator'))
{
header( 'Location: http://scrapbookcampus.com/register-basic-scrap-course-with-psp/' ) ;
}
else
{}
?>


This way doesn't have the <head> code in it. This way the page will not view first. However, it will take just a bit longer to load.

Re: Conditional redirect to another page

PostPosted: August 14th, 2011, 12:06 pm
by Bruce C
For the place holder, try taking it out. If it's showing, then it's not gonna do anything anyhow.

Re: Conditional redirect to another page

PostPosted: August 14th, 2011, 12:16 pm
by cassel
Hum... just used that code and i do NOT get a redirect at all if i click on the Basic Scrap in the navigation menu while logged out. I notice that the code gets all jumbled in the html of WP so maybe that is a problem? I'll try formatting it to see, but right now, i do not get the redirect that i was getting before.

EDIt: i formatted the code as you posted it, and it does not change. I do not get the redirect anymore from the course listing to the sales page if NOT logged in.

It is just odd that it works fine in one direction and not in the other one.

Re: Conditional redirect to another page

PostPosted: August 14th, 2011, 12:22 pm
by Bruce C
Hmm, guess your server doesn't like the PHP code.

Anyway, you could try to use the JavaScript code again, but make sure it's at the top of the page. I'm guessing you put it at the bottom since the code was down there.

EDIT: I just checked your page. It looks like you might have forgotten the beginning <?php

Re: Conditional redirect to another page

PostPosted: August 14th, 2011, 12:27 pm
by cassel
Yeah, i put it at the bottom because the theme uses leafs and the content leaf (which would hold the code) has those social media buttons incorporated and since i cannot figure out how to remove those from individual pages, putting the leaf on top would make those appear on top with a white empty space.

If nothing else, it MIGHT be a compromise. However, i will look at putting all the page content in the content leaf instead of an html leaf. That might work in including the code on top.

I'll let you know
(but why it works in one way and not the other is beyond me!)

Re: Conditional redirect to another page

PostPosted: August 14th, 2011, 12:33 pm
by Bruce C
Did you already try putting the <?php on the code?

Re: Conditional redirect to another page

PostPosted: August 14th, 2011, 12:41 pm
by cassel
No idea why it was not working before, but it does now. It has a slight flickering, but i think i can live with that.

For the sale page, i used this code:
Code: Select all
<?php if (current_user_can('access_s2member_ccap_basic') && !current_user_can('administrator')){ ?><script type="text/javascript">window.location = 'http://scrapbookcampus.com/welcome-to-the-basic-scrapping-course/';</script><?php } else {?><?php } ?>


and for the student page, i used:
Code: Select all
<?php if (!current_user_can('access_s2member_ccap_basic') && !current_user_can('administrator')){ ?><script type="text/javascript">window.location = 'http://scrapbookcampus.com/register-basic-scrap-course-with-psp/';</script><?php } else {?><?php } ?>


Now, i was able to simply put the code in the Headway theme HTML leaf and NOT in the WP page, which made it easier to manipulate. I am pretty sure i will reuse that coding in future pages!!!
Thanks.

Re: Conditional redirect to another page

PostPosted: August 14th, 2011, 12:44 pm
by Bruce C
Great! Happy you got it fixed up.
:D