2

User photos don't appear to be saved in the same method as Assets. I'm looking to do a remote image (from plugin) as the user profile image. I've got the path saving to the column, but the image is not rendering. Anything special I need to do to get that to render?

$user = craft()->users->getUserById($userId);
$user->photo = $gravatarPath;
craft()->users->saveUser($user);
1

Can a user photo support a remote image?

The answer to that is currently "no", in Craft 2.x. However in the upcoming Craft 3.x, user profile photos are proper "assets" and can be saved to any asset source.

I'm looking to do a remote image (from plugin) as the user profile image. I've got the path saving to the column, but the image is not rendering. Anything special I need to do to get that to render?

I assume you're just ignoring Craft's default user profile "photo" field and adding your own custom one? Or are you trying to replace the profile field that Craft uses to display profile photos in the CP with your own custom one. I'm having a hard time seeing how you'd pull off the later in the current version of Craft 2.x.

  • Awesome. To the second question, I'm not replacing the field, just using the onActivateUser event to grab the Gravatar URL and save to user photo. That all is working, the image just isn't rendering in the user profile area. *Updated question with a bit more context. – Ryan Shrum May 5 '15 at 22:41
  • Is it a 404? What's the URL if you view source? – Brad Bell May 5 '15 at 22:57
  • It's returning an image path: domain.com/admin/resources/userphotos/user@email.com/100/http://… If I go to that path, I get a Craft error: Page Not Found The requested URL was not found on this server. I thought I maybe was exceeding the 100 char length on that field, but the string is only 63 chars/ – Ryan Shrum May 5 '15 at 23:09
  • You must have the "userEmailAsUsername" config setting set. Pretty sure there is a bug when that is set where Craft will choke on the @ symbol as a folder name. – Brad Bell May 5 '15 at 23:42
  • The directory seems to be working. If I add an avatar via upload, it works fine and creates the dir with the @ in it (with or without the config setting). I don't think the image is being processed; do you think that has to do with the Gravatar URL not having an extension? – Ryan Shrum May 6 '15 at 13:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.