I recently redesigned a client’s existing EE site and we implemented the gravatar plugin. It’s fabulous, except previously the client allowed people to comment without providing an email address. They’ve since been schooled on the dangers of that, but on old entries it will sometimes spit out errors if there’s a comment on the page from someone without an email address present.
Notice: Undefined index: email in /home/client_name/htdocs/ee/system/plugins/pi.gravatar.php on line 33
Is there a way to correct this without the user having to go back through a few thousand and close the offending comments? An upgrade to the plugin or a variable I’m unaware of maybe?
Thanks so much! 😊
I don’t see Les Jenkins around as much anymore, so I’ll hop in here, Joelle. If you open the plugin, on line 33 you’ll see:
$email = $query->row['email'];
change that to:
$email = (isset($query->row['email'])) ? $query->row['email']: '';
It obviously won’t make the Gravatar work since there’s no email address, but it will squash that error.
Does the default=”http://www.somesite.com/someimage.jpg” parameter not work when not provided with an e-mail address then?
If you create your links using the plugin like below :
{exp:weblog:entries weblog="photos" limit="1" entry_id="10"}
<h1>{title}</h1>
{exp:gravatar email=
{/exp:weblog:entries}
Obviously ignore the entry_id=”10” part as that was just for my test purposes but if there isn’t a valid e-mail address provided or an e-mail address at all then it should spit out the image provided by the default parameter.
Don’t know if that helps at all?
Also hopefully I am looking at the same plugin that you are talking about - plugin link?
Best wishes,
Mark
I don’t know if it is just me though but I just tried the plugin when I posted above but didn’t provide an e-mail address to the plugin and it still uses the default image. Is that not what we are referring to?
Something like this :
{exp:weblog:entries weblog="photos" limit="1" entry_id="10"}
<h1>{title}</h1>
{exp:gravatar email=
{/exp:weblog:entries}
or this :
{exp:weblog:entries weblog="photos" limit="1" entry_id="10"}
<h1>{title}</h1>
{exp:gravatar default=
{/exp:weblog:entries}
In the first example the e-mail parameter is there but isn’t supplied with an address and in the second one the parameter is completely removed from the plugin tag. Obviously the second one isn’t much use but in the case of the first I placed in incorrect e-mail addresses and also just left the e-mail address blank and it still spits out the default parameter image. I admit I have only tried this with the weblog tag and admit to having overlooked that you (Joelie) had originally mentioned that you are using this in comments but I guess it would still work the same wouldn’t it? As in if an e-mail address isn’t given then it will use the default parameter instead of giving an error?
Best wishes,
Mark
Yes I did look at the error but as I can’t reproduce this error when testing the plugin I was going by what had been said here :
Quote “…but on old entries it will sometimes spit out errors if there’s a comment on the page from someone without an email address present.”
I took it (sorry if I misunderstood?) that Joelie meant that for any comments where an e-mail address hadn’t been provided in the past that this was what was causing the error? Is that not what was meant then? I ask because although I have only tested the plugin very quickly and with the default code that was provided with the plugin I can get it to spit out a default image when there isn’t an e-mail provided which is what I thought we were after? Perhaps we could see Joelies full code so that we can all test this out from the same view-point?
Best wishes,
Mark
Mark, I know you want to help, but my first post to Joelle identifies and solves the problem. There’s no reason to test it with various tag usage, or to attempt to recreate it; she’s not making up an error, and even if she were doing something “wrong”, EE and its add-ons should never lead to PHP errors. Look at the code, it attempts to access a variable even if it’s not set.
if ($email == "" && $name != "")
{
$sql = "SELECT email FROM exp_members WHERE screen_name = '$name'";
$query = $DB->query($sql);
$email = $query->row['email'];
}
There’s no conditional to make sure that the query actually returned results before trying to access data from a row. So if you have a screen name, but no email address, and there’s no registered user by the screen name, you’ll get the PHP error.
EDIT - Sorry just saw you posted whilst I was testing and posting.
Okay just as a quick test I placed this on to one of my live sites (now taken off again)
{exp:comment:entries sort="asc" limit="20"}
{exp:gravatar email=
{/exp:comment:entries}
If a person doesn’t provide an e-mail address at all in the comment entry form then it will spit out the Google image. If they have provided an e-mail then it will (as long as they have a Gravatar) spit that out instead. If they provide an e-mail address but they don’t have a Gravatar then it will again spit out the Google image.
This was all done with the standard comments form and comments entry code from the ExpressionEngine documentation and the standard plugin code for the Gravatar plugin provided.
Perhaps you could provide us with a broken down version of the code you are using on the template Joelie because I just tried this with the default items as I have listed above and it all works fine as far as I can see.
Also perhaps try a new template with the bare minimum on it such as just the exp:comment:entries tag and the image link as above and see what you get?
Best wishes,
Mark
There’s no conditional to make sure that the query actually returned results before trying to access data from a row. So if you have a screen name, but no email address, and there’s no registered user by the screen name, you’ll get the PHP error.
Okay I admit I’m a bit confused by all of this but then didn’t know exactly where the error was coming from as I’m not a code guru like yourself Derek 😉 so was just trying to see if this happened on my install too. I did not mean to confuse it was more that I was confused as it does work in comments even if you don’t provide an e-mail address which is what I thought was being said was happening.
Joelie please feel free to ask Derek to collapse or delete all my replies if they are of no help at all.
Best wishes,
Mark
Hi Derek,
Please feel free to delete or collapse my posts preferably after Joelie has read them as I do and I don’t understand I’m afraid.
I do understand more or less from the stand-point of the code that you have pointed out from the plugin but I don’t understand how to get this to reproduce with comments as I have tested this with a live site of mine with the comment form code and if I provide an e-mail and I have a Gravatar it shows up, if I provide an e-mail but don’t have a Gravatar then I get the default image or if I don’t provide an e-mail at all then I still get the default image so even though the code you have posted there does more or less make sense to me (as you are probably aware from looking at the exceptionally simple plugins I have made that I only have a limited knowledge of programming) I still can’t get it to reproduce any errors.
I’m not trying to throw you off at all Joelie by what I had said, far from it, I was just trying to help in that I thought it might be something else that was causing the problem but on that count I am obviously much mistaken.
Derek if as a closer to this you could possibly either post on here a walkthrough of how to get this error to appear or better still if it would be best to keep that out of this post to prevent it from becoming even longer perhaps PM me with a walkthrough then I can see exactly what is happening first hand. As all I had to go on was that this was with the comments on a site and comments that didn’t have an e-mail address then this is all I could test with on my site. Sorry for taking the thread off the beaten track as it were but as I only had that knowledge to go on and I’m not a superb coder like yourself then this is what I was working with at the time 😉
Signing off so that this thread doesn’t grow and grow and grow.
Best wishes,
Mark
Hi Derek,
Thanks for the reply. As per my post here I am now guessing that we are talking about a different plugin? The reason I ask is that on the documentation that I saw for it - http://expressionengine.com/downloads/details/ee_gravatar/ it only mentions using the {email} variable and that would be the only thing I would expect to use seeing as how the Gravatar system works with e-mails only.
I have just searched on the internet and came across the author of the plugins site and found that yes he does mention on that page you can use either {email} or {name} but he does also state :
“It is recommended that you use email for comment and entry loops and name for display in member profile templates, but feel free to experiment.”
As I hadn’t seen this documentation only the documentation on the ExpressionEngine site then this is what I was going by. Also I know that now I have read on Les’s site that he says you can use either he does recommend {email} for comments and {name} for profile templates. I know he says you are free to experiment but now that I have seen that if it were me I would have tried the {email} variable first and probably would never have had that error.
As there was no link to the Gravatar plugin in Joelies first post I always search this sites Add-Ons library first to see if that is what someone is referring to and so I saw the documentation there which doesn’t mention about using a {name} variable at all.
Now I see where the confusion has arisen. 😉
Best wishes,
Mark
We’re talking about the same plugin, Mark - different usage: check your plugin manager after installing. Sorry for the discrepancy between that and the add-on description, but let’s not dwell on details that are irrelevant to the described problem. Instead of changing the course of a discussion before the original poster even has a chance to reply, perhaps wait and see. It seems obvious that you didn’t understand the solution that I gave, which gave you a poor foundation to begin recommending other ideas and devolving into a discussion about how the Gravatar plugin works. That conversation is fine, but better if you had started your own topic. Since it contains a more detailed description of the source of the error, I’ll not split our comments to another discussion, but I am going to collapse all of the others, so that only those directly on topic remain visible in the thread by default.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.