Skip to content

Commit

Permalink
Pass down args to srcset function
Browse files Browse the repository at this point in the history
  • Loading branch information
gchtr committed Mar 2, 2022
1 parent 76cc0da commit 85a77c4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 6 additions & 4 deletions functions-images.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,20 @@ function get_timber_image_src( $timber_image, $size ) {
/**
* Returns the srcset for a TimberImage.
*
* @param int|Timber\Image $timber_image Instance of Timber\Image or attachment ID.
* @param string|array $size Size key or array of the image to return.
* @param int|Timber\Image $timber_image Instance of Timber\Image or attachment ID.
* @param string|array $size Size key or array of the image to return.
* @param array $args Optional args for the srcset.
*
* @return string|bool Image src. False if image can’t be found or no srcset is available.
*/
function get_timber_image_srcset( $timber_image, $size ) {
function get_timber_image_srcset( $timber_image, $size, $args = [] ) {
$image = Timmy::get_image( $timber_image, $size );

if ( ! $image ) {
return false;
}

return $image->srcset();
return $image->srcset( $args );
}

/**
Expand Down
7 changes: 7 additions & 0 deletions lib/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,13 @@ public function src_default() {
return $src_default;
}

/**
* Gets the srcset for an image.
*
* @param array $args Optional. Args for the srcset.
*
* @return false|string
*/
public function srcset( $args = [] ) {
$args = wp_parse_args( $args, [
'webp' => $this->is_webp(),
Expand Down

0 comments on commit 85a77c4

Please sign in to comment.