The plugin does not allow other plugins that use get_avatar to work
-
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!
- The topic ‘The plugin does not allow other plugins that use get_avatar to work’ is closed to new replies.