• Resolved designerthan

    (@designerthan)


    I’m a theme developer and I am currently developing and setting up a theme and WordPress installation for a European customer.
    I am adding the avatar over the “avatar_defaults” hook. Does anybody have an idea whats the matter with that?

    The page I need help with: [log in to see the link]

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author pepe

    (@pputzer)

    Hi @designerthan, can you share code snippets of what you are hooking exactly? avatar_defaults is only about the option value to user-visible label mapping, not any actual image.

    Thread Starter designerthan

    (@designerthan)

    Hi @pputzer, thanks for the fast answer. Here the code how I am integrating the gravatar image

    // Custom Gravatar in Settings > Discussion
    function dtNature_gravatar ($avatar_defaults)
    {
        $myavatar = esc_url( get_template_directory_uri() )  . '/assets/img/gravatar.png';
        $avatar_defaults[$myavatar] = "Nature Feelings Gravatar";
        return $avatar_defaults;
    }
    add_filter('avatar_defaults', 'dtNature_gravatar'); // Custom Gravatar in Settings > Discussion
    Plugin Author pepe

    (@pputzer)

    Thanks. After a quick search, I’ve seen that several tutorials use the filter like this, but I think it’s actually edge-case usage depending on an implementation detail of the Gravatar service (instead of the documented avatar-related functions):

    The key is used as a option value for the “default image” property and passed to get_avatar() et al. The built-in defaults all use a slug like mystery or monsterid, not an actual image. A custom default image should be rendered by also adding a filter on get_avatar_url. However, in stock WordPress, ultimately everything gets passed to gravatar.com and if the d parameter of the API call is not one of the pre-defined slugs, it will be interpreted as an image URL to load.

    Since Avatar Privacy does not render default avatars via Gravatar.com, no valid URL is generated (since get_avatar_url() knows nothing about your key) and thus the included blank.gif is used instead. As this pattern seems to be a widespread pattern, I’ll probably add support for it in a future release, but for now, also filtering get_avatar_url would seem to be the only option.

    Thread Starter designerthan

    (@designerthan)

    Thanks for digging into it and explaining the problem so clearly. I get it.
    I tried to understand how I could solve it, but I can’t find the solution. Is there a way I can get it to work? If yes, what would be your suggestion?
    I would be very glad for some help.

    By the way, I tried to dig into your code and it is one of the best commented codes I have seen and I am a software developer myself. Thanks for your job.

    If you can tell me which function and file I should look at, I could maybe alter it so it works cause I have all set up at my laptop. But I dont know if it is too advanced for me.

    Plugin Author pepe

    (@pputzer)

    Directly working with get_avatar_url is probably too complicated, but this should work (it is all untested, though):

    // Custom avatar in Settings > Discussion
    function dtNature_avatar ($avatar_defaults)
    {
        $avatar_defaults['nature_feelings'] = "Nature Feelings Avatar";
        return $avatar_defaults;
    }
    add_filter('avatar_defaults', 'dtNature_avatar');
    
    function dtNature_avatar_url( $url, $hash, $size, $args )
    {
        if ( 'nature_feelings' === $args['default'] ) {
            $url = get_template_directory_uri() . '/assets/img/gravatar.png';
        }
    
        return $url;
    }
    add_filter('avatar_privacy_default_icon_url', 'dtNature_avatar_url', 9, 4 );

    However, you can also set a custom default avatar by simply uploading the image when Avatar Privacy is activated. Doing it with the code above will not take advantage of dynamic resizing etc.

    Thread Starter designerthan

    (@designerthan)

    Thank you for your answer. The thought of mine was to add a image, which meets the design of the theme, but I am not in hurry and as fix for now I will do like you suggest to just upload it with your plugin and wait for the released version.

    The code looks like it works and is good to know how it would work. Thank you for your help.
    Should I set this thread to solved or shall I wait for the release?

    Have a good night. It’s midnight for me.

    Plugin Author pepe

    (@pputzer)

    Will be fixed in 2.3.4.

    Plugin Author pepe

    (@pputzer)

    Fixed in 2.3.4.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Themes custom avatar turns blank after activating’ is closed to new replies.