Support » Plugin: UsersWP - User Registration & User Profile » The plugin does not allow other plugins that use get_avatar to work

  • Resolved José Miguel

    (@jomisica)


    Hello devs,

    Your plugin does not allow other plugins that work with the get_avatar filter to work.

    In this case I am referring to Optimum Gravatar Cache. However any other can not work.

    I’ve been analyzing your plugin and found in the file
    includes/helpers/misc.php in line 1513 the following code:

    
    remove_all_filters('get_avatar');
    

    It removes all filters from all plugins that have already added this filter. This way all the plugins that have been processed before usersWP are left without their filters. Only the plugins that are initialized after usersWP survive.

    And I can not understand why.

    I have a simple modification that allows your plugin to work normal and allows others to do so.
    Of course you can and should arrange a better solution however this works.

    Comment this code:

    
    // remove_all_filters('get_avatar');
    

    As well as making a small change to the “uwp_modify_get_avatar” function, which allows you to test if we are dealing with gravatar from gravatar.com

    The function would look like this:

    
    function uwp_modify_get_avatar($avatar, $id_or_email, $size, $default, $alt, $args)
    {
        $user = false;
    
        if (is_numeric($id_or_email)) {
            $id = (int)$id_or_email;
            $user = get_user_by('id', $id);
        } elseif (is_object($id_or_email)) {
            if (!empty($id_or_email->user_id)) {
                $id = (int)$id_or_email->user_id;
                $user = get_user_by('id', $id);
            }
        } else {
            $user = get_user_by('email', $id_or_email);
        }
    
        if ($user && is_object($user)) {
            $avatar_thumb = uwp_get_usermeta($user->data->ID, 'uwp_account_avatar_thumb', '');
            if (!empty($avatar_thumb)) {
                $uploads = wp_upload_dir();
                $upload_url = $uploads['baseurl'];
                if (substr($avatar_thumb, 0, 4) !== "http") {
                    $avatar_thumb = $upload_url . $avatar_thumb;
                }
                $avatar = "<img alt='{$alt}' src='{$avatar_thumb}' class='avatar avatar-{$size} photo' height='{$size}' width='{$size}' />";
            } else {
                // Check if it is not an image of gravatar.com
                // If it is not an image of gravatar.com is because another plugin has already modified it.
                if (strpos($avatar, 'gravatar.com') === false) {
                    return $avatar;
                }
                $default = uwp_get_default_avatar_uri();
                $args = get_avatar_data($id_or_email, $args);
                $url = $args['url'];
                $url = remove_query_arg('d', $url);
                $url = add_query_arg(array('d' => $default), $url);
                if (!$url || is_wp_error($url)) {
                    return $avatar;
                }
                $avatar = '<img src="' . $url . '" class="gravatar avatar avatar-' . $size . ' uwp-avatar" width="' . $size . '" height="' . $size . '" alt="' . $alt . '" />';
            }
        }
    
        return $avatar;
    }
    

    Thank you!

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

    (@stiofansisland)

    Hey @jomisica,

    Though we try to avoid using that we had to set that for a few support requests we had in the past. Its been there for over a year with no issues, we will however add a developer option to our settings to allow you to “switch” this off.

    As for your function (FYI you still have a print_r in there), all we are doing is adding our own default fallback to the gravatar call, if we returned early and they have no image set then it would not be able to use the one from our settings.

    The setting will be in the next release, if you need it sooner, it will likely be in a commit later today here: https://github.com/UsersWP/userswp/

    If i can help further just let me know.

    Thanks,

    Stiofan

    Thread Starter José Miguel

    (@jomisica)

    Hello @stiofansisland,

    The print_r is only for analysis, it is in a local site to test no problem. I already modified the post.

    I’m waiting for the commit.

    Thank you!

    Thread Starter José Miguel

    (@jomisica)

    Hello @stiofansisland

    I believe that an option on the usersWP options page that allows the user to choose whether the plugin should manage the gravatar or not, would really be the best option. Because it allowed the user to use other plugins to manage the gravatars.

    UsersWP also does not have full support for gravatars, there is no support for the filter:
    ‘get_avatar_url’

    It also does not support filters for buddypress:
    ‘bp_core_fetch_avatar’,
    ‘bp_core_fetch_avatar_url’

    Plugin Author Stiofan

    (@stiofansisland)

    Hi @jomisica,

    Sorry the option did not make it in that last release, there was a bug fix that took priority, i have created a task for the developer to update you here once done. I have also added a task to check the get_avatar_url filter.

    I believe that an option on the usersWP options page that allows the user to choose whether the plugin should manage the gravatar.

    All you would need to do is not use the feature?

    UWP and BuddyPress are not intended to be used together, they are alternatives of each other, they would both be fighting over profile images and pages.

    Thanks,

    Stiofan

    Thread Starter José Miguel

    (@jomisica)

    Hello @stiofansisland

    Yes, if it is possible for the user of UWP disable this feature will allow the user to use another plugin to manage the gratarars. There is no need for a plugin to remove filters from other plugins. In this way the UWP will adapt to more projects, with different characteristics.

    Thank you!

    Plugin Author Patrik

    (@wpdev10)

    Hi,

    We have fixed this and will be available in the next release of the plugin. Here is the PR which contains the changes:https://github.com/UsersWP/userswp/pull/271 You check if it works fine as you suggested or not and let us know your inputs.

    Regards,
    Patrik

    Thread Starter José Miguel

    (@jomisica)

    Hello @wpdev10 @stiofansisland

    I’ve tested the modifications and it really works.

    Thank you!

    Plugin Author Stiofan

    (@stiofansisland)

    You are welcome, thanks for reporting and your patience on our fix 🙂

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘The plugin does not allow other plugins that use get_avatar to work’ is closed to new replies.