Automattic / Automattic/jetpack
Site accelerator/Photon processes Gravatars w/ already processed image URLs (resulting in broken images)
- Dominant language
- PHP
- Stars
- 1.8k
- Forks
- 898
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 774
Description
## The Issue
I am filtering the `default` parameter for Gravatars with an image URL I obtain via `wp_get_attachment_image_src`. (Photon processes this URL).
The URL is processed a 2nd time as Photon filters the Gravatar output. The result is a broken URL that looks like:
`https://secure.gravatar.com/avatar/e72425f2a568bcfb144b752a793c1384?s=48&d=https%3A%2F%2Fi2.wp.com%2Fsixprizes.com%2Fwp-content%2Fuploads%2F2017%2F05%2Ftwitter.png%3Ffit%3D512%252C512%26ssl%3D1&r=pg`
which redirects to:
`https://i1.wp.com/i2.wp.com/sixprizes.com/wp-content/uploads/2017/05/twitter.png?ssl=1` (which is invalid)
Normally, Jetpack will bail on processing the URL when it has `i2.wp.com` as its host. (See `validate_image_url` in `class.photon.php`.) However, it doesn't pick up on this when it's parameterized in a Gravatar URL.
I am working around the issue by removing the `jetpack_photon_override_image_downsize` filter before getting the image with `wp_get_attachment_image_src`.
## Function
```php
add_filter( 'pre_get_avatar_data', 'ac_pre_get_avatar_data_default_url', 10, 2 );
function ac_pre_get_avatar_data_default_url( $args, $id_or_email ) {
// Photon: Disable
add_filter( 'jetpack_photon_override_image_downsize', '__return_true' );
// Get image
$image_src = wp_get_attachment_image_src( 65904, 'full' );
// Photon: Reenable
remove_filter( 'jetpack_photon_override_image_downsize', '__return_true' );
// Image URL
$image_url = $image_src[0];
// Set default
$args['default'] = $image_url;
// Return
return $args;
}
```
## URL when Photon is disabled
`https://secure.gravatar.com/avatar/e72425f2a568bcfb144b752a793c1384?s=96&d=https%3A%2F%2Fsixprizes.com%2Fwp-content%2Fuploads%2F2017%2F05%2Ftwitter.png&r=pg`
which redirects to:
`https://i1.wp.com/sixprizes.com/wp-content/uploads/2017/05/twitter.png?ssl=1` (which is valid)
Contributor guide
Assessment
This issue has not been assessed yet.