• Thanks for a great plugin!

    The avatars are displaying exactly as they should when get_avatar() is called. However, I have a plugin installed that calls get_avatar_url(), which still returns the Gravatar url. Can the next update include an override for this function as well?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Ronald Huereca

    (@ronalfy)

    Sorry for the delay. What theme are you using?

    The plugin is not replacing the url in that function.
    Here is a quick fix for it.

    
        function profile_img_url($url, $id_or_email, $args = array()) {
            //Get user data
            if (is_numeric($id_or_email)) {
                $user = get_user_by('id', (int) $id_or_email);
            } elseif (is_object($id_or_email)) {
                $comment = $id_or_email;
                if (empty($comment->user_id)) {
                    $user = get_user_by('id', $comment->user_id);
                } else {
                    $user = get_user_by('email', $comment->comment_author_email);
                }
                if (!$user)
                    return $url;
            } elseif (is_string($id_or_email)) {
                $user = get_user_by('email', $id_or_email);
            } else {
                return $url;
            }
            if (!$user)
                return $url;
            $user_id = $user->ID;
            $profile_post_id = absint(get_user_option('metronet_post_id', $user_id));
    
            if (0 === $profile_post_id || 'mt_pp' !== get_post_type($profile_post_id)) {
                return $url;
            }
            $defaults = array(
                'size' => 'thumbnail',
                'attr' => '',
            );
            $args = wp_parse_args($args, $defaults);
            extract($args); //todo - get rid of evil extract
            //Implode Classes if set and array - dev note: edge case
            if (is_array($attr) && isset($attr['class'])) {
                if (is_array($attr['class'])) {
                    $attr['class'] = implode(' ', $attr['class']);
                }
            }
    
            $post_thumbnail_id = get_post_thumbnail_id($profile_post_id, $size, false, $attr);
            $profile_img_url = wp_get_attachment_image_src($post_thumbnail_id);
            return $profile_img_url[0];
        }
        add_filter('get_avatar_url', 'profile_img_url', 10, 3);
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Override get_avatar_url()’ is closed to new replies.