Hey,
i've got "Notice: Undefined property: stdClass::$roles in user_access()" error on node with comments. User pictures are not loaded.
Error is from gravatar.module line 176.
elseif (!user_access('use gravatar', $account) || (user_access('disable own gravatar', $account) && isset($account->data['gravatar']) && !$account->data['gravatar'])) {
return variable_get('user_picture_default', '');
}
Problem is that $account is not user account (and it does not have $roles property) but some kind of comment object.
To fix problem i've added
$account = _gravatar_load_account($account);
on first line of _gravatar_get_account_user_picture function. I'm not sure it is correct way of fixing this problem.
greetings
Isilweo
Comments
Comment #1
RobNL commentedThanks! I had the same experience. Your solution works. But only the line
$account = _gravatar_load_account($account);will do fine.Comment #2
thedavidmeister commentedRan into this issue while pulling in user pictures with display suite. When inspecting a backtrace of the error notice it seemed that display suite wasn't sending through an $account object with roles for superuser (uid = 1).
Bumping this to major because when the error triggers no user pictures will display for any comments on the page.
Patch attached, rolled against latest 7.x-1.x
Comment #4
thedavidmeister commentedNo tests were found?? I think the patch is fine but the testbot hasn't been setup right.
Comment #5
dpiComment #8
thedavidmeister commented#2: 1440846-ensure-gravatar-account-loaded-2.patch queued for re-testing.
Comment #10
thedavidmeister commentedfwiw, patch applied cleanly to my build via drush when I added it to a makefile.
Comment #11
thedavidmeister commented#2: 1440846-ensure-gravatar-account-loaded-2.patch queued for re-testing.
Comment #13
thedavidmeister commentedComment #14
thedavidmeister commentedI added an empty test to GravatarFunctionalTest to try and make the testbot happy.
Comment #16
thedavidmeister commenteddamn test bot.
Anyway, I noticed that Gravatar always ensures that its $account object is fully loaded internally and this is actually a bug in Display Suite #1166928: Display Suite does not honor Gravatar when displaying a user's picture as DS calls _gravatar_get_account_user_picture() directly inside ds_return_picture() and only conditionally loads the $account object.
The patches here work, so you can use those if you want to fix the problem that way, but I've filed a corresponding patch at the DS end in that issue, so efforts should be directed over there for the final solution.