Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Comment avatar functions ignore $args['default'] #2468

Closed
tylersticka opened this issue Jul 14, 2021 · 0 comments · Fixed by #2786 or #2913 · May be fixed by #3003
Closed

Comment avatar functions ignore $args['default'] #2468

tylersticka opened this issue Jul 14, 2021 · 0 comments · Fixed by #2786 or #2913 · May be fixed by #3003

Comments

@tylersticka
Copy link

Expected behavior

If you want to customize the default avatar in WordPress from a plugin or theme, normally you'd do so via one of the avatar filters like so:

function example_custom_avatar_data($args, $id_or_email) {
  $args['default'] = 'https://placeimg.com/96/96/animals';
  return $args;
}

add_filter('pre_get_avatar_data', 'example_custom_avatar_data', 10, 2);

In which case any request for a Gravatar that does not exist will instead display our custom default image:

Screen Shot 2021-07-14 at 9 32 55 AM

This functionality is helpful in cases where we want to extend WordPress's default avatar functionality dynamically via a plugin.

Actual behavior

In Timber, the following code in the context of a post comment…

<img src="{{comment.avatar}}" width="96" height="96" alt="">

…will never display the image path set via the filter using $args['default']. It will always fall back to get_option('avatar_default') unless $default is provided from the template.

Screen Shot 2021-07-14 at 9 37 12 AM

Steps to reproduce behavior

  1. Activate the Timber starter theme.
  2. Add the Twig snippet above to the theme's templates/comment.twig.
  3. Add the PHP snippet above to the theme's functions.php or to a new plugin.
  4. Navigate to wp-admin/options-discussion.php and scroll to the "Default avatar" section. All default avatars should display the image path provided in the PHP snippet.
  5. Navigate to a post containing comments with a default image visible. Observe that the image displayed does not match what was defined in the filter.

What version of WordPress, PHP and Timber are you using?

  • WordPress 5.7.2
  • PHP 7.4.1
  • Timber 1.18.2

How did you install Timber? (for example, from GitHub, Composer/Packagist, WP.org?)

  • WP.org, synced locally via Local
Levdbas added a commit that referenced this issue Aug 1, 2023
see the issue for details on the typos fixed

fixes issue #2468
@Levdbas Levdbas linked a pull request Dec 13, 2023 that will close this issue
@Levdbas Levdbas added 2.0 and removed 2.x Future labels Dec 14, 2023
@Levdbas Levdbas added this to the 2.0.1 milestone Dec 14, 2023
@Levdbas Levdbas modified the milestones: 2.0.1, 2.1.0 Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants