trying to find the way to allocate a country flags instead using MisteryMan icon, Gravatar or User Avatar.
Any help or suggestion about where to start?
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It only takes a minute to sign up.
Sign up to join this communitytrying to find the way to allocate a country flags instead using MisteryMan icon, Gravatar or User Avatar.
Any help or suggestion about where to start?
You need to hook into get_avatar() somewhere. There are plenty of options:
<img>
tag from, so it might be simpler to hook into get_avatar_url(), which itself is just a wrapper around get_avatar_data(), and leave get_avatar() to still build the HTML for youand the obvious point to hook get_avatar_data is the pre_get_avatar_data hook:
/**
* Filters whether to retrieve the avatar URL early.
*
* Passing a non-null value in the 'url' member of the return array will
* effectively short circuit get_avatar_data(), passing the value through
* the {@see 'get_avatar_data'} filter and returning early.
*
* @since 4.2.0
*
* @param array $args Arguments passed to get_avatar_data(), after processing.
* @param mixed $id_or_email The Gravatar to retrieve. Accepts a user ID, Gravatar MD5 hash,
* user email, WP_User object, WP_Post object, or WP_Comment object.
*/
$args = apply_filters( 'pre_get_avatar_data', $args, $id_or_email );
which is slightly complicated in that you need to process many different types of input, but you can borrow the code from just below that call to do that. In your filter handler you'll need to work out which country the user, email or comment is from and then set $args['url']
to be the flag image you want to use.
However that's not that simple in itself: