Support » Plugin: Avatar Manager » No custom default avatar in settings–>discussion

  • Resolved cag8f

    (@cag8f)


    Hello. I have just installed the plugin for the first time. Your screenshots indicate that my settings–>discussion screen should have a “Custom Default Avatar” setting, but mine does not (screenshot). Am I misunderstanding something?

    Thanks in advance.

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Cătălin Dogaru

    (@cdog)

    Hey cag8f,

    It does support it. You just need to define a new default image. To do this please see Can I create a default custom avatar? from the FAQs. Let me know if this helps or if you need further support.

    Best,
    Cătălin

    Thanks for that! I was able to upload a suitable image and implement the code. But the image is still broken in the back-end (screenshot). Thoughts on this?

    edit: I have confirmed that the link to the image is functional. I can open it in a browser without issue.

    • This reply was modified 3 years, 4 months ago by cag8f.
    Plugin Author Cătălin Dogaru

    (@cdog)

    Hey,

    Glad you got it working! I should update the docs, it’s better to use get_stylesheet_directory_uri() instead of get_bloginfo( 'template_directory' ):

    
    $avatar_url = get_stylesheet_directory_uri() . '/images/avatar.png';
    

    Please try with these changes and let me know if it works in both front-end and back-end.

    Best,
    Cătălin

    OK I tried your edits but am still encountering a broken image link. As a test, I tried to just hardcode the avatar URL. Here is my code:

    function custom_avatar_defaults ( $avatar_defaults ) {
        $avatar_url = 'http://test01.com/wp-content/uploads/2016/12/avatar-test.jpeg';
        $avatar_defaults[$avatar_url] = __( 'Custom Default Avatar', 'mytextdomain' );
        return $avatar_defaults;
    }
    add_filter( 'avatar_defaults', 'custom_avatar_defaults' );

    Thoughts? What is the ‘mytextdomain’ parameter? Do I need to change this?

    Thanks.

    Plugin Author Cătălin Dogaru

    (@cdog)

    It seems that you are almost ready to go 🙂 As I don’t have access to your WordPress site I’ll take the default theme (twentysixteen) as an example. How to add a custom default avatar:

    1. Copy the new image to your theme files (this would be wp-content/themes/twentysixteen/img/default-avatar.png).
    2. Add the mentioned code to your theme’s functions.php file (this would be wp-content/themes/twentysixteen/functions.php).

    It looks like you’ve uploaded the image through media library. You can change the code to reflect the current image URL as you did (grab it from media library) or move the image to your theme files as described in the FAQs. I recommend the latter.

    The text domain is used for translations (and it’s usually the theme name, i.e. twentysixteen). More about this is covered in the WordPress docs:
    https://developer.wordpress.org/themes/functionality/internationalization/

    Let me know if this helps.

    Best,
    Cătălin

    OK I have copied the image to the same directory as my style.css. Then I ensured that the following code was in my functions.php file:

    function custom_avatar_defaults ( $avatar_defaults ) {
        $avatar_url = get_stylesheet_directory_uri() . '/avatar-test.jpeg';
        echo $avatar_url;
        $avatar_defaults[$avatar_url] = __( 'Custom Default Avatar', 'mytextdomain' );
        return $avatar_defaults;
    }
    add_filter( 'avatar_defaults', 'custom_avatar_defaults' );

    But I am still encountering the same issue. The page is still looking for the image at gravatar.com (screenshot). I have confirmed that $avatar_url is indeed pointing to the correct image.

    • This reply was modified 3 years, 3 months ago by cag8f.
    Plugin Author Cătălin Dogaru

    (@cdog)

    The code looks good. Make sure the image filename is as is avatar-test.jpeg (and not avatar-test.jpg or avatar-test.JPEG).

    The src attribute of the img element should look like this:
    0.gravatar.com/avatar/94342688a50851cbd0e95f91986e973e?s=32&d=http://wordpress.localhost/wp-content/themes/twentyfifteen/avatar-test.jpeg&f=y&r=g

    This means that the user avatar is queried from Gravatar (first part of the URL) and if none is availalbe will default to your custom default image (second part of the URL http://wordpress.localhost/wp-content/themes/twentyfifteen/avatar-test.jpeg).

    If you are running your WordPress site from localhost it will display a broken image (this is normal as Gravatar won’t be able to access your local URL to fetch the image). Just check that the src attribute is correct. Uploading the site to your host (making it public) would work as expected.

    Best,
    Cătălin

    >> If you are running your WordPress site from localhost it will display a broken image (this is normal as Gravatar won’t be able to access your local URL to fetch the image).

    OK this was the issue. I am developing my site locally. When I pushed it to the web server, the image displayed without issue. Maybe a note about that in your FAQ–it caused both of us a little grief.

    Anyway, I very much appreciate your assistance. We can consider this resolved.

    Plugin Author Cătălin Dogaru

    (@cdog)

    Great, thanks a lot for your patience and for involvement! This for sure helps poiting where is room for improvement. I’ll complete the docs to make it clear.

    Best,
    Cătălin

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘No custom default avatar in settings–>discussion’ is closed to new replies.