Man2u2uk Posted May 1, 2012 Share Posted May 1, 2012 Hi All, I'm currently using the s2member plugin for wordpress to allow me to create a client portal where users can log in and visit their own secure unique page. (This uses custom capability and the page must be called the same as their username.) But then i also have people that just log on to view my blog and are not clients and do not have pages created for them. I have the following code: <a href="?php echo S2MEMBER_CURRENT_USER_LOGIN; ?>/">Client Area</a> This works fine when logged in as a user who has a page created but gives an 404 error for a user that does not have a page. My question is: Could the above code be wrapped in an if statement to say that if the S2MEMBER_CURRENT_USER_LOGIN does not = post_name then redirect them to the home page? Quote Link to comment Share on other sites More sharing options...
Man2u2uk Posted May 1, 2012 Author Share Posted May 1, 2012 I doubt this is correct. But i need something like this: $S2MEMBER_CURRENT_USER_LOGIN = username; if ( $username == post_name ) { header( 'Location: http://www.yoursite.com?username' ) ; } else { header( 'Location: http://www.example.com/home' ) ; } to link in with: <a href="?php echo S2MEMBER_CURRENT_USER_LOGIN; ?>/">Client Area</a> Quote Link to comment Share on other sites More sharing options...
darkfreaks Posted May 2, 2012 Share Posted May 2, 2012 http://thedeadone.net/download/tdo-mini-forms-wordpress-plugin/ i think this is what you are looking for? something where non registered users have the option to edit stuff correct? Quote Link to comment Share on other sites More sharing options...
Man2u2uk Posted May 2, 2012 Author Share Posted May 2, 2012 Unfortunatly not darkfreaks, Maybe i did not explain my self correctly. The way my client portal works is that if i have a user called Alex and a page called Alex and he clicks on the "Client Area" link. The following code will take them to their page <a href="?php echo S2MEMBER_CURRENT_USER_LOGIN; ?>/">Client Area</a> The issue i have is that if i have a user called Ben and he does not have a page and clicks on the "Client Area" link he will get a 404 error. I somehow need to wrap an if statement around the following link <a href="?php echo S2MEMBER_CURRENT_USER_LOGIN; ?>/">Client Area</a> Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 2, 2012 Share Posted May 2, 2012 <a href="?php echo (isset(S2MEMBER_CURRENT_USER_LOGIN) ? S2MEMBER_CURRENT_USER_LOGIN : 'home_page_url');?>/">Client Area</a> You might need to also check the string length of the login. Also, you have it set as a constant in some of your examples, and a variable in others, so figure out which it is. Quote Link to comment Share on other sites More sharing options...
Man2u2uk Posted May 2, 2012 Author Share Posted May 2, 2012 Thanks for the reply. I will test this code out this evening when i get home. As per your comment: Also, you have it set as a constant in some of your examples, and a variable in others, so figure out which it is. It should be S2MEMBER_CURRENT_USER_LOGIN Quote Link to comment Share on other sites More sharing options...
Man2u2uk Posted May 2, 2012 Author Share Posted May 2, 2012 Hi, I have just logged onto my machine and pasted the following code, <a href="<?php echo (isset(S2MEMBER_CURRENT_USER_LOGIN) ? S2MEMBER_CURRENT_USER_LOGIN : 'home');?>/">Client Area</a> but it gives the following error: Parse error: syntax error, unexpected ')', expecting T_PAAMAYIM_NEKUDOTAYIM A quick Google mentions its about the scope operator ( :: ) but i'm not sure what this means or how to fix it? Quote Link to comment Share on other sites More sharing options...
mikosiko Posted May 2, 2012 Share Posted May 2, 2012 try <a href="<?php echo (defined('S2MEMBER_CURRENT_USER_LOGIN') ? S2MEMBER_CURRENT_USER_LOGIN : 'home');?>/">Client Area</a> Quote Link to comment Share on other sites More sharing options...
Man2u2uk Posted May 2, 2012 Author Share Posted May 2, 2012 Thanks, <a href="<?php echo (defined('S2MEMBER_CURRENT_USER_LOGIN') ? S2MEMBER_CURRENT_USER_LOGIN : 'home');?>/">Client Area</a> That code stopped the error but its still redirecting the users who don't have a page created to an 404 error. i think if S2MEMBER_CURRENT_USER_LOGIN does not match post_name then redirect needs to be added into the code somehow? Quote Link to comment Share on other sites More sharing options...
mikosiko Posted May 2, 2012 Share Posted May 2, 2012 maybe just because your 'home' could be incorrectly defined... so <a href="home/"> need to be reviewed for existence Quote Link to comment Share on other sites More sharing options...
Man2u2uk Posted May 2, 2012 Author Share Posted May 2, 2012 Sorry. I understand what you mean but not sure how to implement it? i tried the following: <a href="<?php echo (defined('S2MEMBER_CURRENT_USER_LOGIN') ? S2MEMBER_CURRENT_USER_LOGIN : '<a href="home/"</a>>');?>/">Client Area</a> But that did nothing as i thought it was as i'm a PHP noob lol Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 2, 2012 Share Posted May 2, 2012 How does the value of S2MEMBER_CURRENT_USER_LOGIN relate to whether or not they have a page? Quote Link to comment Share on other sites More sharing options...
Man2u2uk Posted May 2, 2012 Author Share Posted May 2, 2012 It doesn't. S2MEMBER_CURRENT_USER_LOGIN just grabs the current logged in users username and because i hyperlinked it if a page exists with the same name it just takes them to it and if it does not match takes the user to a 404 page.. post_name is what wordpress uses to store the page name in the database. Quote Link to comment Share on other sites More sharing options...
mikosiko Posted May 2, 2012 Share Posted May 2, 2012 in your website... if you move your cursor to whatever point that link to your home page, how that link looks like exactly... maybe something like "www.yourwebsitehere/index.php" ?? Quote Link to comment Share on other sites More sharing options...
Man2u2uk Posted May 2, 2012 Author Share Posted May 2, 2012 Hi, Regardless of what user i log on as if i hover over the "Client Area" link it always links to the username of whatever user is logged in. http://www.yourwebsitehere/usersname Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 2, 2012 Share Posted May 2, 2012 So do you realize why, if they don't relate to each other, making the IF statement dependent on that won't work? try it with the post_name variable instead. Quote Link to comment Share on other sites More sharing options...
Man2u2uk Posted May 2, 2012 Author Share Posted May 2, 2012 Sorry jesirose, maybe they do sort of link together as they equal the same value? I tried the following but that just redirected everyone to the home page: <a href="<?php echo (defined('post_name') ? post_name : 'home');?>/">Client Area</a> I thought an IF statement would work as we could check to see if S2MEMBER_CURRENT_USER_LOGIN is equal to post_name if show redirect to their page and if not redirect to the home page? Quote Link to comment Share on other sites More sharing options...
mikosiko Posted May 2, 2012 Share Posted May 2, 2012 and what about <a href="<?php echo (defined('S2MEMBER_CURRENT_USER_LOGIN') ? S2MEMBER_CURRENT_USER_LOGIN : post_name);?>/">Client Area</a> Quote Link to comment Share on other sites More sharing options...
Man2u2uk Posted May 2, 2012 Author Share Posted May 2, 2012 Still the same Quote Link to comment Share on other sites More sharing options...
mikosiko Posted May 2, 2012 Share Posted May 2, 2012 before this line <a href="<?php echo (defined('S2MEMBER_CURRENT_USER_LOGIN') ? S2MEMBER_CURRENT_USER_LOGIN : post_name);?>/">Client Area</a> did you check that the constant S2MEMBER_CURRENT_USER_LOGIN and/or post_name are not null or empty? Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 2, 2012 Share Posted May 2, 2012 is post_name a constant or a variable? defined() is for constants. Quote Link to comment Share on other sites More sharing options...
Man2u2uk Posted May 2, 2012 Author Share Posted May 2, 2012 I think post_name is a variable. its stored in the database as post_name. Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 2, 2012 Share Posted May 2, 2012 Where is it in the code though? Just because the column is called post_name, the variable might be $post_name or $postName; or $post, you need to find it in the code. Quote Link to comment Share on other sites More sharing options...
Man2u2uk Posted May 3, 2012 Author Share Posted May 3, 2012 before this line <a href="<?php echo (defined('S2MEMBER_CURRENT_USER_LOGIN') ? S2MEMBER_CURRENT_USER_LOGIN : post_name);?>/">Client Area</a> did you check that the constant S2MEMBER_CURRENT_USER_LOGIN and/or post_name are not null or empty? Hi mikosiko, that is the only line of code i have. Where is it in the code though? Just because the column is called post_name, the variable might be $post_name or $postName; or $post, you need to find it in the code. Hi jesirose, post_name (without the $ )is referenced alot throughout the wordpress code. Quote Link to comment Share on other sites More sharing options...
Man2u2uk Posted May 14, 2012 Author Share Posted May 14, 2012 I have now solved this issue. - Please close. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.