Jump to content

Hello $user_identity/$comment_author/"visitor"


Recommended Posts

Hi there,

Wasted the last hour of my life trying to get this to work, no matter what I try it fails.

Anyway, here's the scenario. My wordpress blog theme has a function that when a person who has commented on my site before leaves a comment, it says "Welcome back $comment_author"

This is terrible, cookies don't last long enough and people don't see the message. I want it to say "Welcome back $user_identity" and if there's no user identity present, "Welcome back $comment_author" and then if there's no $comment_author present, "Welcome visitor."

Sounds simple? It's not. Here's the code that's there all ready, the code I want modified:
[code]<?php if( '' !== $comment_author ) { ?>

<p>Welcome back <b><?php echo $comment_author; ?></b>


<?php } ?>[/code]I can get it to say "Welcome back $user_identity" easy enough, but I want the system to LOOK for $user_identity, then if it's not found look for $comment_author then if that's not found user "visitor"

It sounds simple but when trying to use numerous elses and ifs the page simply breaks. This is soo annoying. I mean, I can even get it to check for one then use "visitor" but I simply can't make it check for one, then another, then visitor.

The above code is [i]all[/i] you need to provide, the $user_identity etc. are already provided, you don't need to create a code to find them, if you know what I mean.

[b]EDIT:[/b] I will make a post on my blog advertising your site if you help me with this!!
Link to comment
https://forums.phpfreaks.com/topic/30275-hello-user_identitycomment_authorvisitor/
Share on other sites

Snippet updated, mistake removed.

Added information: If you are the person which fixes this, I will make an post on my forum advertising the site of your choice.

Come on, this must be easy, numerous elses/ifs?!?

Link to site in question: http://www.mbhoy.com (feel free to remove if in violation of tos)
Tried the logical:[code]<?php
if( '' !== $user_identity ) {

echo "back <b>$user_identity</b>.</p>";

} elseif( '' !== $comment_author ) {
echo "back <b>$comment_author</b>.</p>";
} else {
echo "visitor.</p>"

} ?>[/code] and the page breaks.
Where would the $user information come from?
Where is $comment_user coming from??
Not sure where these are coming from but try this out
[code]<?php
if(isset($user_identity)){
$visitor = $user_identity;
} else {
  if(isset($comment_author)){
    $visitor = $comment_author;
  } else {
  $visitor = "visitor";
  }
}
echo "Welcome Back $visitor";
?>[/code]

Ray

Without anything to search on your will not have much luck.

Ray
Trust me, they're coming from somewhere in wordpress, when echoing randomly they come out fine, it's the whole else/elseif/if thing that seems to be failing on me.

[code]<?php if ( '' !== $user_identity ) : ?>

<?php echo $user_identity; ?>

<?php elseif ( '' !== $comment_author ) : ?>
<?php echo $comment_author; ?>
<?php else : ?>
<?php echo "visitor."; ?>[/code]^^ fails too!

And when I say fails, I mean the page completely breaks and looks horrible.
[code]<?php
if(isset($user_identity)){
$visitor = $user_identity;
} else {
  if(isset($comment_author)){
    $visitor = $comment_author;
  } else {
  $visitor = "visitor";
  }
} ?>

<p>Welcome back <b><?php echo $visitor;?></b>[/code]

^^ that's to be compatible with your earlier mentioned lay-out.

The visitor problem is probably because craygo's script just checks is the variable $comment_author or $user_identity [b]exist[/b]. It's possible that they're created but not filled in. If you want us to make a compatible script, you need to provide where those variables are coming from and what creates them based on which parameters.

You could try something like this:

[code]<?php
if(isset($user_identity)){
if($user_identity == ""){
$visitor = "visitor";
}
else{
$visitor = $user_identity;
}
} else {
  if(isset($comment_author)){
if($comment_author == ""){
$visitor = "visitor";
}
else{
$visitor = $comment_author;
}
  } else {
  $visitor = "visitor";
  }
} ?>

<p>Welcome back <b><?php echo $visitor;?></b>[/code]

Don't you just love if-then clauses :D
No guaranteed success :p

[­quote author=freeloader link=topic=118228.msg482950#msg482950 date=1165874817]
The visitor problem is probably because craygo's script just checks is the variable $comment_author or $user_identity exist. It's possible that they're created but not filled in. If you want us to make a compatible script, you need to provide where those variables are coming from and what creates them based on which parameters.[/quote]
Yeah, you got it just as I did. Final code was:
[­code]<?php
if(isset($user_identity)){
$visitor = $user_identity;
echo "Welcome Back, <b>$visitor</b>";
} else {
  if( '' !== $comment_author ){
    $visitor = $comment_author;
echo "Welcome Back <b>$visitor</b>";
  }
}
?>[/code]
Which displays no welcome to first time visitors, only to people who have registered/commented beforehand.

Thanks all, if you'd like to contact me with links I'll link to you in a post on my blog as a reward.

Edited by requinix
removing email address by request
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.