Skip to content

Commit

Permalink
Post Images: don't fetch Gravatars from post content (#38692)
Browse files Browse the repository at this point in the history
Fixes #38501
  • Loading branch information
jeherve authored Aug 5, 2024
1 parent 5676d62 commit e2ce031
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: bugfix

Sharing: do not include Gravatar images in Open Graph Meta tags.
6 changes: 6 additions & 0 deletions projects/plugins/jetpack/class.jetpack-post-images.php
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,12 @@ public static function from_html( $html_or_id, $width = 200, $height = 200 ) {
if ( stripos( $img_src, '/smilies/' ) ) {
continue;
}

// Do not grab Gravatar images.
if ( stripos( $img_src, 'gravatar.com' ) ) {
continue;
}

// First try to get the width and height from the img attributes, but if they are not set, check to see if they are specified in the url. WordPress automatically names files like foo-1024x768.jpg during the upload process
$width = (int) $image_tag->getAttribute( 'width' );
$height = (int) $image_tag->getAttribute( 'height' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ public function test_from_html_double_quotes() {
$this->assertEquals( 200, $result[0]['src_height'] );
}

/**
* Ensure that Gravatar images are not included in the list of images extracted from the post contents (html).
*
* @since $$next-version$$
*/
public function test_from_html_gravatar() {
$s = '<img class="jetpack-blogging-prompt__answers-gravatar wp-hovercard-attachment grav-hashed grav-hijack" aria-hidden="true" src="https://0.gravatar.com/avatar/89f071d1932fe8c204a3381e00bd6794ddc28bcdb0642f29c9f48beaa5e277af?s=96&d=identicon&r=G">';

$result = Jetpack_PostImages::from_html( $s );

$this->assertIsArray( $result );
$this->assertEmpty( $result );
}

/**
* Test image size extract in src filename
*
Expand Down

0 comments on commit e2ce031

Please sign in to comment.