Last active
February 5, 2021 12:43
-
-
Save aldavigdis/2a60a3eaee171c1a1ad474af435ad12b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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