Skip to content

Instantly share code, notes, and snippets.

@aldavigdis
Last active February 5, 2021 12:43
Show Gist options
  • Save aldavigdis/2a60a3eaee171c1a1ad474af435ad12b to your computer and use it in GitHub Desktop.
Save aldavigdis/2a60a3eaee171c1a1ad474af435ad12b to your computer and use it in GitHub Desktop.
<?php
class DonnaPix {
const PIC_IPSUM_URL = 'https://picsum.photos/';
public function __construct() {
add_filter(
'wp_calculate_image_srcset',
array( $this, 'srcset_filter' ),
10,
1
);
add_filter(
'wp_get_attachment_url',
array( $this, 'attachment_url_filter' ),
10,
2
);
}
public function attachment_url_filter( $url, $attachment_id ) {
return $this::PIC_IPSUM_URL . '600';
}
public function srcset_filter( $sources ) {
if ( is_array( $sources ) ) {
foreach ( $sources as $key => $s ) {
$sources[ $key ]['url'] = $this::PIC_IPSUM_URL . $key;
}
}
return $sources;
}
}
$donna_pix = new DonnaPix();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment