wordpress is_user_logged_inproblem
-
Hello,
No idea why but this does not work in my wordpress post:
[php]if (is_user_logged_in()) {
echo ‘[/php]helllllllllllllllllloooooooooooooooooo[php]‘;
} else {
echo ‘[/php]helllllllllllllllooooooooooooo222222[php]‘;
}[/php]I have of course added a “php” plugin that enables php code in post…the php output works as I have tried it with echo” but the code above won’t recognized if the user is logged in.
Any idea why please?
I am using wordpress 3.3
Thank you,
Ben
-
Try this and let me know if you get different results:
[php]if (is_user_logged_in()) { echo 'helllllllllllllllllloooooooooooooooooo'; } else { echo 'helllllllllllllllooooooooooooo222222'; }[/php]
Hi James,
Thank you for your help.
This is very strange because the way you wrote it works, it detects I am logged in and output the right “echo”.
Now if I populate both the “echo” with my widget code(js), It does not output them on the page, logged in or not, I tried to write the expression using your way by using [php] and [/php] at the top and bottom of the code and some of the php code is showing up in the post.
<p><!–Flash Game Start–>
<embed src=”https://games.mochiads.com/c/g/santas-battlefield/SantaZombieShooter.swf” menu=”false” quality=”high” width=”640″ height=”535″ type=”application/x-shockwave-flash” pluginspage=”https://www.macromedia.com/go/getflashplayer”></embed>
<!–Flash Game End–></p>
<p>[php]
if ( is_user_logged_in() ) {
<!–leaderboard Start–>
echo ‘[/php]<div id=”leaderboard_widget”></div>
<p><script src=”https://xs.mochiads.com/static/pub/swf/leaderboard.js” type=”text/javascript”>
</script>
<script type=”text/javascript”>Mochi.showLeaderboardWidget({game: “santas-battlefield”, partnerID: “ffa761aaf7”, id: “leaderboard_widget”})</script>
<!–leaderboard End–><!–Bridge Start–></</p>
<div id=”leaderboard_bridge”></div>
<p><script src=”https://xs.mochiads.com/static/pub/swf/leaderboard.js” type=”text/javascript”></script>
<script type=”text/javascript”>var options = {partnerID: “ffa761aaf7”, id: “leaderboard_bridge”};
options.username = “[php]global $current_user; echo $current_user->user_login;[/php]“;
Mochi.addLeaderboardIntegration(options);
</script>[php]‘;
<!–Bridge End–>
} else {
echo ‘[/php]</p>
<div id=”leaderboard_widget”></div>
<p><script src=”https://xs.mochiads.com/static/pub/swf/leaderboard.js” type=”text/javascript”>
</script>
<script type=”text/javascript”>Mochi.showLeaderboardWidget({game: “santas-battlefield”, partnerID: “ffa761aaf7”, id: “leaderboard_widget”})</script>
<!–leaderboard End–><!–Bridge Start–></</p>
<div id=”leaderboard_bridge”></div>
<p><script src=”https://xs.mochiads.com/static/pub/swf/leaderboard.js” type=”text/javascript”></script>
<script type=”text/javascript”>var options = {partnerID: “ffa761aaf7”, id: “leaderboard_bridge”};
options.denyScores = “Login to Example to submit scores!”;
Mochi.addLeaderboardIntegration(options);
</script>[php]‘;
<!–Bridge End–>
}
[/php]Please see this page:
https://www.maltaon(dot)com/test
Please replace the (.) , I do not want Google to crawl my site yet as it is not finished.
hi there its quite dificult to read your code you didn’t put it in a code block however i think the problem you are having is because you don’t need to echo the output of the if statement as it is incorrect syntax for a string
<?php if ( is_user_logged_in() ) { ?> <div id="leaderboard_widget"></div> <script src="https://xs.mochiads.com/static/pub/swf/leaderboard.js" type="text/javascript"></script> <script type="text/javascript">Mochi.showLeaderboardWidget({game: "santas-battlefield", partnerID: "ffa761aaf7", id: "leaderboard_widget"})</script> <div id="leaderboard_bridge"></div> <script src="https://xs.mochiads.com/static/pub/swf/leaderboard.js" type="text/javascript"></script> <script type="text/javascript"> var options = {partnerID: "ffa761aaf7", id: "leaderboard_bridge"}; options.username = "<?php global $current_user; echo $current_user->user_login;?>"; Mochi.addLeaderboardIntegration(options); </script> <?php } else { ?> <div id="leaderboard_widget"></div> <script src="https://xs.mochiads.com/static/pub/swf/leaderboard.js" type="text/javascript"></script> <script type="text/javascript"> Mochi.showLeaderboardWidget({game: "santas-battlefield", partnerID: "ffa761aaf7", id: "leaderboard_widget"}) </script> <div id="leaderboard_bridge"></div> <script src="https://xs.mochiads.com/static/pub/swf/leaderboard.js" type="text/javascript"></script> <script type="text/javascript"> var options = {partnerID: "ffa761aaf7", id: "leaderboard_bridge"}; options.denyScores = "Login to Example to submit scores!"; Mochi.addLeaderboardIntegration(options); </script> <?php } ?>
if you are trying to echo all that html you don’t need to use the echo statment
<?php if ($contition) { ?> <div> <p></p> </div> <?php } // end if ?>
<p> <?php if ( is_user_logged_in() ) { ?> <div id="leaderboard_widget"></div> <p><script src="https://xs.mochiads.com/static/pub/swf/leaderboard.js" type="text/javascript"> </script> <script type="text/javascript">Mochi.showLeaderboardWidget({game: "santas-battlefield", partnerID: "ffa761aaf7", id: "leaderboard_widget"})</script> <!--leaderboard End--> <!--Bridge Start--></</p> <div id="leaderboard_bridge"></div> <p><script src="https://xs.mochiads.com/static/pub/swf/leaderboard.js" type="text/javascript"></script> <script type="text/javascript">var options = {partnerID: "ffa761aaf7", id: "leaderboard_bridge"}; options.username = "<?php global $current_user; echo $current_user->user_login;?>"; Mochi.addLeaderboardIntegration(options); </script> <?php } else { ?> </p> <div id="leaderboard_widget"></div> <p><script src="https://xs.mochiads.com/static/pub/swf/leaderboard.js" type="text/javascript"> </script> <script type="text/javascript">Mochi.showLeaderboardWidget({game: "santas-battlefield", partnerID: "ffa761aaf7", id: "leaderboard_widget"})</script> <!--leaderboard End--> <!--Bridge Start--></</p> <div id="leaderboard_bridge"></div> <p><script src="https://xs.mochiads.com/static/pub/swf/leaderboard.js" type="text/javascript"></script> <script type="text/javascript">var options = {partnerID: "ffa761aaf7", id: "leaderboard_bridge"}; options.denyScores = "Login to Example to submit scores!"; Mochi.addLeaderboardIntegration(options); </script> <?php } ?>
Sorry musicaldustbin but you have lost me on that one
I’m on the road so it’s a little tougher to give a proper response on my phone. The issue is you aren’t writing proper php syntax. Also you keep closing and opening your [php] in weird ways. My suggestion would be to write the whole thing in one large php statement without trying to open and close it repeatedly. Being sure to properly echo all HTML.
I’m pretty sure that it would print properly if you were to do this.
how come there is <p> tags around everything ? i hope you arn’t pasting this into the WYSIWYG :S
i have 2 widgets with gaming scores, one widget will take the logged in username name and post it to the leaderboard while the other widget will tell the people to register on the site in order to post a score.
Thats the way the game publisher wrote his code, now I need a function that output widget 1 if the user is logged in or widget 2 if he isn’t logged in.Thank you, I hope you understand a bit more what I am trying to achieve.
Ben
Hi MusicalDustBin,
I am trying to post this code into a wordpress post, I have downloaded the php plugin called “allow php in post and pages”. By pasting the code into the page, it should work, actually this one works fine.
[php]if (is_user_logged_in()) {
echo ‘helllllllllllllllllloooooooooooooooooo’;
} else {
echo ‘helllllllllllllllooooooooooooo222222’;
}[/php]Now the reason you see <p> tags everywhere is because I copied it from wordpress directly, here is my version from the php editor:
<?php if ( is_user_logged_in() ) { <!--leaderboard Start--> echo '<div id="leaderboard_widget"></div> <p><script src="https://xs.mochiads.com/static/pub/swf/leaderboard.js" type="text/javascript"> </script> <script type="text/javascript">Mochi.showLeaderboardWidget({game: "santas-battlefield", partnerID: "ffa761aaf7ff9d0d", id: "leaderboard_widget"})</script> <!--leaderboard End--><br> <!--Bridge Start--> <div id="leaderboard_bridge"></div> <script src="https://xs.mochiads.com/static/pub/swf/leaderboard.js" type="text/javascript"></script> <script type="text/javascript">var options = {partnerID: "ffa761aaf7ff9d0d", id: "leaderboard_bridge"}; options.username = "global $current_user; echo $current_user->user_login;"; Mochi.addLeaderboardIntegration(options); </script>'; <!--Bridge End--> } else { echo ' <div id="leaderboard_widget"></div> <script src="https://xs.mochiads.com/static/pub/swf/leaderboard.js" type="text/javascript"> </script> <script type="text/javascript">Mochi.showLeaderboardWidget({game: "santas-battlefield", partnerID: "ffa761aaf7ff9d0d", id: "leaderboard_widget"})</script> <!--leaderboard End--><br> <!--Bridge Start--></ <div id="leaderboard_bridge"></div> <p><script src="https://xs.mochiads.com/static/pub/swf/leaderboard.js" type="text/javascript"></script> <script type="text/javascript">var options = {partnerID: "ffa761aaf7ff9d0d", id: "leaderboard_bridge"}; options.denyScores = "Login to Example to submit scores!"; Mochi.addLeaderboardIntegration(options); </script>'; <!--Bridge End--> } ?>
My problem really is not to have this code working on a plain php file but rather in a wordpress post. I just cannot output the required widget in a post via this code. But strangely this code here without javascript in it works perfectly
[php]if (is_user_logged_in()) {
echo ‘helllllllllllllllllloooooooooooooooooo’;
} else {
echo ‘helllllllllllllllooooooooooooo222222’;
}[/php]
This is what I cannot work out. I used the exact same php code but added javascript in between the quotes, that’s all. therefore it must have a conflict in the js itself….but what?Thank you,
Ben
Yeah thought that’s what you must be doing but it can get a bit sketchy sometimes and won’t validate… but any way….
I prematurely pressed enter when writing the response before i have cleaned up the code a little now hopefully it reads a little better.
(you should be able to cut and paste it)You will see in the code above that you don’t need to use echo to get your desired response.
Also i presume you aren’t coding this is something that checks syntax. I would suggesting getting textmate or coda, this will help a lot if you plan on doing more web dev
Thanks you for your help,
Ok, I have added your code and now the output (source) shows both widgets and not 1 at the time, this is weird:
[Code moderated as per the Forum Rules. Please use the pastebin]
[please ensure that your code is enclosed in backticks (`) or use the code button.]
The plugin I am using to output php on the wordpress post is “Allow PHP in posts and pages” is this can help.
I have been on it for 3 days now……..using 3 forums at the same time and no one seem to be able to find a solution, this is just so strange….. Is it a problem with wordpress itself?
hey its not a problem with wordpress your code didn’t post before becuase you didn’t “Put code in between
backticks
.” so im not sure what you were askingthe plugin certainly isn’t the ideal way to create the page and may, cause problems with things. You are better off creating a new page template and assigning it to a page.
If your using a post your options get a bit more limited and requires a more complicated solution if you are not to use the plugin.
if you post your code again using “backticks” i will have a quick look for you and see if i can figure out whats not happening
Nope, it’s not a problem with WordPress. If you look at my post above, it’s a problem with your syntax which was the issue with your very first snippet you started this thread with. I could easily fix it but I’m traveling all day and won’t have Internet on my laptop again until Tuesday.
I also agree with musicaldustbin, this situation is generally best suited for a custom page template. Another solution would be to apply a filter to the content of the particular page or post but would require a bit more WordPress prowess, depending on your experience. ??
- The topic ‘wordpress is_user_logged_inproblem’ is closed to new replies.