Use custom gravatar on wordpress child theme

266 views Asked by At

I can't manage to get the code working to show my default gravatar image for my child wordpress theme.

This is the code I am using:

//Custom Gravatar
add_filter( 'avatar_defaults', 'new_custom_default_gravatar' );
function new_custom_default_gravatar ($avatar_defaults) {
  $myavatar = get_stylesheet_directory_uri() . '/gravatar/favicon.png';
  $avatar_defaults[$myavatar] = "My Custom Gravatar";
  return $avatar_defaults;
}

I do see the clickable option on the backend settings. This is what I get when I inspect the section:

<label>
  <input type="radio" name="avatar_default" id="avatar_http://mysubdomain.mydomain.org/wordpress/wp-content/themes/my-theme-child-theme/gravatar/favicon.png" value="http://mysubdomain.mydomain.org/wordpress/wp-content/themes/my-theme-child-theme/gravatar/favicon.png"> 
  <img alt="" src="http://1.gravatar.com/avatar/419a9e4a2c6ea719fd7d300cbd38e24d?s=32&amp;d=http%3A%2F%2Fmysubdomain.mydomain.org%2Fwordpress%2Fwp-content%2Fthemes%2Fmy-theme-child-theme%2Fgravatar%2Ffavicon.png&amp;r=g&amp;forcedefault=1" srcset="http://1.gravatar.com/avatar/419a9e4a2c6ea719fd7d300cbd38e24d?s=64&amp;d=http%3A%2F%2Fmysubdomain.mydomain.org%2Fwordpress%2Fwp-content%2Fthemes%2Fmy-theme-child-theme%2Fgravatar%2Ffavicon.png&amp;r=g&amp;forcedefault=1 2x" class="avatar avatar-32 photo" height="32" width="32"> My Custom Gravatar
</label>

If I visit the image link I get a redirect to:

http://i0.wp.com/2Fmysubdomain.mydomain.org/wordpress/wp-content/themes/my-theme-child-theme/gravatar/favicon.png

With the message:

We cannot complete this request, remote data was invalid

My folder and file permissions are 777. Any ideas?

1

There are 1 answers

0
AudioBubble On

This problem is known, here is some description:

https://en.gravatar.com/site/implement/images/

When you include a default image, Gravatar will automatically serve up that image if there is no image associated with the requested email hash. There are a > few conditions which must be met for default image URL:

  • MUST be publicly available (e.g. cannot be on an intranet, on a local development machine, behind HTTP Auth or some other firewall etc). Default images are passed through a security scan to avoid malicious content.
  • MUST be accessible via HTTP or HTTPS on the standard ports, 80 and 443, respectively.
  • MUST have a recognizable image extension (jpg, jpeg, gif, png)
  • MUST NOT include a querystring (if it does, it will be ignored)

So this is a duplicate of https://wordpress.stackexchange.com/questions/159482/custom-gravatar-not-working