Skip to content

Commit

Permalink
Merge pull request #7 from eighteen73/develop
Browse files Browse the repository at this point in the history
Fix image srcset rewrites
  • Loading branch information
brettsmason authored Jun 12, 2024
2 parents 80eb214 + dce26c3 commit 20bd124
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions includes/classes/RemoteFiles/RemoteFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public function setup() {

// Update Image URLs
add_filter( 'wp_get_attachment_image_src', [ $this, 'image_src' ] );
add_filter( 'wp_calculate_image_srcset', [ $this, 'image_srcset' ], 10, 5 );
add_filter( 'wp_get_attachment_image_attributes', [ $this, 'image_attr' ], 99 );
add_filter( 'wp_prepare_attachment_for_js', [ $this, 'image_js' ], 10, 3 );
add_filter( 'the_content', [ $this, 'image_content' ] );
Expand Down Expand Up @@ -109,6 +110,22 @@ public function image_attr( array $attr ): array {
return $attr;
}

/**
* Modify Image Srcset
*
* @param array $attr The image srcset
*
* @return array
*/
public function image_srcset( $sources ) {

foreach ( $sources as $source => $source_data ) {
$sources[$source]['url'] = $this->update_image_url( $source_data['url'] );
}

return $sources;
}

/**
* Modify Image for Javascript
* Primarily used for media library
Expand Down

0 comments on commit 20bd124

Please sign in to comment.