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

RobNL’s picture

Thanks! I had the same experience. Your solution works. But only the line $account = _gravatar_load_account($account); will do fine.

thedavidmeister’s picture

Priority: Normal » Major
Status: Active » Needs review
StatusFileSize
new569 bytes

Ran 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

Status: Needs review » Needs work

The last submitted patch, 1440846-ensure-gravatar-account-loaded-2.patch, failed testing.

thedavidmeister’s picture

No tests were found?? I think the patch is fine but the testbot hasn't been setup right.

dpi’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 1440846-ensure-gravatar-account-loaded-2.patch, failed testing.

The last submitted patch, 1440846-ensure-gravatar-account-loaded-2.patch, failed testing.

thedavidmeister’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 1440846-ensure-gravatar-account-loaded-2.patch, failed testing.

thedavidmeister’s picture

fwiw, patch applied cleanly to my build via drush when I added it to a makefile.

thedavidmeister’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 1440846-ensure-gravatar-account-loaded-2.patch, failed testing.

thedavidmeister’s picture

Status: Needs work » Needs review
thedavidmeister’s picture

I added an empty test to GravatarFunctionalTest to try and make the testbot happy.

Status: Needs review » Needs work

The last submitted patch, 1440846-ensure-gravatar-account-loaded-14.patch, failed testing.

thedavidmeister’s picture

Priority: Major » Normal
Status: Needs work » Closed (won't fix)

damn 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.