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™

Conditional redirect to another page

s2Member Plugin. A Membership plugin for WordPress®.

Re: Conditional redirect to another page

Postby cassel » August 9th, 2011, 9:44 pm

Well, yes and no. I tried disabling Exec-PHP; didn't work. At Headway theme support forum, i was suggested to disable s2Member so i could at least edit the code, but that didn't work either. In the end, i had to scratch the page and start all over again. Lucky for me it was just a test page so, nothing was really lost.

Right now, before i use the conditional redirect (which seemed to work!), i need to figure out why i am getting underline of a different color than text in links. I know it has nothing to do with the theme, so i am a bit at loss (since i never edited the CSS file).

http://scrapbookcampus.com/testpage

(the white headers have black underline... weird). If you have any suggestion on that, i am all ear, but if not, i'll have to address that FIRST and the conditional redirect AFTER. :)
User avatar
cassel
Experienced User
Experienced User
 
Posts: 442
Joined: February 17, 2011

Re: Conditional redirect to another page

Postby Cristián Lávaque » August 10th, 2011, 1:38 pm

That's because a text-decoration:underline; in line 44 of http://scrapbookcampus.com/wp-content/t ... 1312942086

You can use Firebug to spot this kind of things. http://getfirebug.com/

About the redirection, instead of the header approach you used earlier, you can try JavaScript, like:

Code: Select all
<script type="text/javascript">window.location = 'http://scrapbookcampus.com/basic-tutorials-for-scrapbooking-with-paintshop-pro/';</script>


I hope that helps.
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Conditional redirect to another page

Postby cassel » August 10th, 2011, 1:57 pm

For the text decoration, somehow i cannot access that link (i get a jumbled up text instead of an expected tidy format). I am not even sure what it looks like and what it should look like (i barely know html). I would have thought that the default value would be to have an underline the same color as the text, especially since i never messed with that file.

Firebug: i was told about that, but i will have to study how to use it because when i was trying to figure out something else, i would not get information on what i was looking for. That is on my to-do list.

For the Java script, does that replace or go with the conditionals (since i want only paying members to be redirected)? And where do i put that? I know even less about Java than i know about HTML (shoudl give you an idea that i know nothing!)
User avatar
cassel
Experienced User
Experienced User
 
Posts: 442
Joined: February 17, 2011

Re: Conditional redirect to another page

Postby Cristián Lávaque » August 10th, 2011, 2:01 pm

Yeah, you'd use that inside the condition or it'll happen for everyone loading the page. Use the HTML editor when you add it, the Visual one will mess it up.
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Conditional redirect to another page

Postby cassel » August 10th, 2011, 2:12 pm

I am not using the HMTL editor or the visual one for this since i am using leafs from Headway Theme. That is why i was locked out before without access through the dashboard. But i`ll try that inside a leaf, using the code within the conditionals. I`ll let you know how it works.
User avatar
cassel
Experienced User
Experienced User
 
Posts: 442
Joined: February 17, 2011

Re: Conditional redirect to another page

Postby Cristián Lávaque » August 10th, 2011, 4:34 pm

OK.
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Conditional redirect to another page

Postby Bruce C » August 10th, 2011, 5:43 pm

Cristián Lávaque wrote:
Code: Select all
<script type="text/javascript">window.location = 'http://scrapbookcampus.com/basic-tutorials-for-scrapbooking-with-paintshop-pro/';</script>



Just a note, whenever a Javascript redirect is put through, it loads the header, and sometimes the contents of the page before redirecting, which is why I posted the php redirect, which loads before the page, therefore it causes less lag.

However, Cristián is correct. That will work also.
~Bruce ( a.k.a. Ace )

If you're interested in a Professional Installation, or Custom Coding Job, you can send your request here.

Proud Supporter of:
The Zeitgeist Movement
and Occupy Everything
User avatar
Bruce C
Experienced User
Experienced User
 
Posts: 337
Joined: July 20, 2011

Re: Conditional redirect to another page

Postby Cristián Lávaque » August 10th, 2011, 6:18 pm

But using header in the post's body I feel you risk some content having been served before the new header and getting an error. Or does WP start serving page later than the point with the redirection header in the post's body?
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Conditional redirect to another page

Postby cassel » August 10th, 2011, 6:30 pm

I'll have to test that since i was not planning on posting in the WP page, but inside a HT leaf!
User avatar
cassel
Experienced User
Experienced User
 
Posts: 442
Joined: February 17, 2011

Re: Conditional redirect to another page

Postby Bruce C » August 10th, 2011, 6:36 pm

It appears that as long as the redirect of PHP is in the <head> tag it does not matter if anything is above it. It is automatically done first.

If you post this into a WordPress post, or just a .php file, it still works the same.
Code: Select all
<body>
Body Text
</body>
<head>
<?php echo "hello"; ?>
<?php header( 'Location: http://google.com/' ) ; ?>
</head>


None of the text shows up, and it redirects as always.
~Bruce ( a.k.a. Ace )

If you're interested in a Professional Installation, or Custom Coding Job, you can send your request here.

Proud Supporter of:
The Zeitgeist Movement
and Occupy Everything
User avatar
Bruce C
Experienced User
Experienced User
 
Posts: 337
Joined: July 20, 2011

Re: Conditional redirect to another page

Postby cassel » August 10th, 2011, 6:41 pm

Silly question: what does that line mean:
<?php echo "hello"; ?>
Is it to be used as is, or only a placeholder?
User avatar
cassel
Experienced User
Experienced User
 
Posts: 442
Joined: February 17, 2011

Re: Conditional redirect to another page

Postby Bruce C » August 10th, 2011, 6:46 pm

Code: Select all
<?php echo "hello" ?>
is the same thing as just typing hello in a html page. Just to show that code before the redirect does not affect it.
~Bruce ( a.k.a. Ace )

If you're interested in a Professional Installation, or Custom Coding Job, you can send your request here.

Proud Supporter of:
The Zeitgeist Movement
and Occupy Everything
User avatar
Bruce C
Experienced User
Experienced User
 
Posts: 337
Joined: July 20, 2011

Re: Conditional redirect to another page

Postby cassel » August 10th, 2011, 7:03 pm

So do i NEED that line?? (i am more confused now!)
User avatar
cassel
Experienced User
Experienced User
 
Posts: 442
Joined: February 17, 2011

Re: Conditional redirect to another page

Postby Cristián Lávaque » August 10th, 2011, 7:10 pm

No, that "hello" was just an example to show me that he could have output before the header line, without getting an error.
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010

Re: Conditional redirect to another page

Postby Bruce C » August 10th, 2011, 7:13 pm

No, those past few posts were just to assure that the PHP redirect was safe enough.

This code:

Code: Select all
<head>
[s2If current_user_can(access_s2member_ccap_basic)]<?php header( 'Location: http://scrapbookcampus.com/basic-tutorials-for-scrapbooking-with-paintshop-pro/' ) ; ?>
[/_s2if]
[s2If !current_user_can(access_s2member_ccap_basic)
[/s2If]
</head>


Should be all you need. Or, as Christian said, you could remove the <head> portion, and instead use:

Code: Select all
[s2If current_user_can(access_s2member_ccap_basic)]
<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]


However, this will cause the contents of your page to first view, as it is NOT loaded before the contents of your page. This should be the only difference.

EDIT:
Took out quotes around access_s2member_ccap_basic.
Last edited by Bruce C on August 13th, 2011, 9:31 pm, edited 2 times in total.
~Bruce ( a.k.a. Ace )

If you're interested in a Professional Installation, or Custom Coding Job, you can send your request here.

Proud Supporter of:
The Zeitgeist Movement
and Occupy Everything
User avatar
Bruce C
Experienced User
Experienced User
 
Posts: 337
Joined: July 20, 2011

Re: Conditional redirect to another page

Postby cassel » August 10th, 2011, 7:22 pm

Well, i will test it and let you know if it does what i want it to do.
User avatar
cassel
Experienced User
Experienced User
 
Posts: 442
Joined: February 17, 2011

Re: Conditional redirect to another page

Postby Bruce C » August 10th, 2011, 7:23 pm

OK, thanks!
~Bruce ( a.k.a. Ace )

If you're interested in a Professional Installation, or Custom Coding Job, you can send your request here.

Proud Supporter of:
The Zeitgeist Movement
and Occupy Everything
User avatar
Bruce C
Experienced User
Experienced User
 
Posts: 337
Joined: July 20, 2011

Re: Conditional redirect to another page

Postby cassel » August 13th, 2011, 8:58 pm

As i am testing, i do not get it to do what i want. Here is the complete code
Code: Select all
[s2If current_user_can("access_s2member_ccap_basic")]<script type="text/javascript">window.location = http://scrapbookcampus.com/welcome-to-the-basic-scrapping-course/';</script>
[/s2If]
[s2If !current_user_can("access_s2member_ccap_basic")]
if you see this, it means you dont have access to the student area and therefore, i will try to sell you the course.... hahaha</br></br>

[/s2If]

and it is on this page:
http://scrapbookcampus.com/test-redirect

If you are not a member or not logged in, you will see a little message saying so. However, if you ARE a logged in member with Basic access, it still stays on the same page. I tested it with a user Member1 (pw: Member1). I know that as an admin, i am not redirected either.

Did i miss something along the way?
User avatar
cassel
Experienced User
Experienced User
 
Posts: 442
Joined: February 17, 2011

Re: Conditional redirect to another page

Postby Bruce C » August 13th, 2011, 9:28 pm

Ah, silly me converting from the original php code.

Just take out the quotes around access_s2member_ccap_basic.
~Bruce ( a.k.a. Ace )

If you're interested in a Professional Installation, or Custom Coding Job, you can send your request here.

Proud Supporter of:
The Zeitgeist Movement
and Occupy Everything
User avatar
Bruce C
Experienced User
Experienced User
 
Posts: 337
Joined: July 20, 2011

Re: Conditional redirect to another page

Postby cassel » August 13th, 2011, 9:33 pm

Almost there. Now, as i am logged in and should have access, i dont see that text anymore, but i am not redirected either. Anything else i am missing?
User avatar
cassel
Experienced User
Experienced User
 
Posts: 442
Joined: February 17, 2011

Re: Conditional redirect to another page

Postby Bruce C » August 13th, 2011, 9:38 pm

The beginning quote around your redirection link is missing.
~Bruce ( a.k.a. Ace )

If you're interested in a Professional Installation, or Custom Coding Job, you can send your request here.

Proud Supporter of:
The Zeitgeist Movement
and Occupy Everything
User avatar
Bruce C
Experienced User
Experienced User
 
Posts: 337
Joined: July 20, 2011

Re: Conditional redirect to another page

Postby Bruce C » August 13th, 2011, 9:39 pm

Wait, before doing that, I would consider using the <?php style tags, so that you do not get locked out.

Use this instead:

Code: Select all
<?php if (current_user_can('access_s2member_ccaps_basic') && !current_user_can('administrator'))
{ ?>
<script type="text/javascript">window.location = 'http://scrapbookcampus.com/basic-tutorials-for-scrapbooking-with-paintshop-pro/';</script>
<?php } else {?>
<?php } ?>


What this will do is not redirect you if you are an administator, so you will not be locked out.
Last edited by Bruce C on August 13th, 2011, 9:58 pm, edited 2 times in total.
~Bruce ( a.k.a. Ace )

If you're interested in a Professional Installation, or Custom Coding Job, you can send your request here.

Proud Supporter of:
The Zeitgeist Movement
and Occupy Everything
User avatar
Bruce C
Experienced User
Experienced User
 
Posts: 337
Joined: July 20, 2011

Re: Conditional redirect to another page

Postby cassel » August 13th, 2011, 9:51 pm

Hum.... still not working. One thing i also notice is that if i copy the code, in wp it just jumbles it all up, without the formatting. I wonder if it can be a problem?
User avatar
cassel
Experienced User
Experienced User
 
Posts: 442
Joined: February 17, 2011

Re: Conditional redirect to another page

Postby Bruce C » August 13th, 2011, 9:54 pm

No, I fixed that code. Sorry, I was just trying not to get you locked out. lol.

That edited code will work now.
~Bruce ( a.k.a. Ace )

If you're interested in a Professional Installation, or Custom Coding Job, you can send your request here.

Proud Supporter of:
The Zeitgeist Movement
and Occupy Everything
User avatar
Bruce C
Experienced User
Experienced User
 
Posts: 337
Joined: July 20, 2011

Re: Conditional redirect to another page

Postby cassel » August 13th, 2011, 9:57 pm

You lost me there. Don't i have to put the viewable content in that code or is it only to put above any content?
User avatar
cassel
Experienced User
Experienced User
 
Posts: 442
Joined: February 17, 2011

PreviousNext

Return to s2Member Plugin

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron