On Retina displays and at zoom is reloaded from Gravatar
-
Hello,
I noticed that on Retina displays and when zooming into the browser above a certain size, Gravatar is reloaded again.
This is because the img tag also contains a srcset attribute in which the URL is not rewritten.
The problem is actually quite simple to solve.
Following code part:
public function filter_get_avatar( $img ) { // Perform a simple strpos() search to determine if there's a need to perform the more expensive regex search and replace. If a site has a lot of non-Gravatar avatars we don't want to bog it down by performing the regex for every single avatar. if ( ! strpos( $img, 'gravatar.com' ) === false ) { // Regex search for src='*gravatar.com*' or src="*gravatar.com*" (case insensitive) and replace with URL for locally stored image. $img = preg_replace( '/src=[\'"].+?gravatar\.com.+?[\'"]/i', 'src="' . plugin_dir_url( __FILE__ ) . 'mystery.jpg"', $img ); } return $img; }
Needs to be extended by one line to look like this:
public function filter_get_avatar( $img ) { // Perform a simple strpos() search to determine if there's a need to perform the more expensive regex search and replace. If a site has a lot of non-Gravatar avatars we don't want to bog it down by performing the regex for every single avatar. if ( ! strpos( $img, 'gravatar.com' ) === false ) { // Regex search for src='*gravatar.com*' or src="*gravatar.com*" (case insensitive) and replace with URL for locally stored image. $img = preg_replace( '/src=[\'"].+?gravatar\.com.+?[\'"]/i', 'src="' . plugin_dir_url( __FILE__ ) . 'mystery.jpg"', $img ); $img = preg_replace( '/srcset=[\'"].+?gravatar\.com.+?[\'"]/i', 'srcset="' . plugin_dir_url( __FILE__ ) . 'mystery.jpg 2x"', $img ); } return $img; }
Would be great if this could possibly be included in a new version.
Otherwise, I have it with me first manually inserted!Maybe it would also make sense to provide the “mystery.jpg” in two different sizes, e.g. 26×26 and 52×52 pixels and to embed it accordingly!
Greetings Sascha
- The topic ‘On Retina displays and at zoom is reloaded from Gravatar’ is closed to new replies.