Skip to content

Commit

Permalink
Merge pull request #2669 from timber/2.x-remove-is-image-method
Browse files Browse the repository at this point in the history
  • Loading branch information
gchtr committed May 20, 2023
2 parents 9d66ca8 + f88c413 commit b71a6bd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 36 deletions.
1 change: 1 addition & 0 deletions docs/v2/upgrade-guides/2.0.md
Expand Up @@ -1001,6 +1001,7 @@ The following functions and properties were **removed from the codebase**, eithe
- `get_url()` – use `{{ image.src }}` instead
- `url()` – use `{{ image.src }}` instead
- `$caption` property – use `caption()` method instead. You can still use `{{ image.caption }}` in Twig. In PHP `$image->caption` also still works because magic properties will automatically resolve to `$image->caption()`.
- `is_image()` – without replacement. Timber now checks whether a post is an image if you use `Timber::get_post()` or `Timber::get_image()` and only returns a `Timber\Image` object for attachments that are images.

### Timber\MenuItem

Expand Down
38 changes: 2 additions & 36 deletions src/Image.php
Expand Up @@ -185,10 +185,6 @@ public function src($size = 'full')
return URLHelper::maybe_secure_url($this->abs_url);
}

if (!$this->is_image()) {
return wp_get_attachment_url($this->ID);
}

$src = wp_get_attachment_image_src($this->ID, $size);
$src = $src[0];

Expand Down Expand Up @@ -350,11 +346,7 @@ protected function get_dimension_loaded($dim = null)
*/
public function srcset(string $size = 'full'): ?string
{
if ($this->is_image()) {
return wp_get_attachment_image_srcset($this->ID, $size) ?: null;
}

return null;
return wp_get_attachment_image_srcset($this->ID, $size) ?: null;
}

/**
Expand All @@ -374,32 +366,6 @@ public function srcset(string $size = 'full'): ?string
*/
public function img_sizes(string $size = 'full'): ?string
{
if ($this->is_image()) {
return wp_get_attachment_image_sizes($this->ID, $size) ?: null;
}

return null;
}

/**
* Checks whether the image is really an image.
*
* @internal
* @return bool Whether the attachment is really an image.
*/
protected function is_image()
{
$src = wp_get_attachment_url($this->ID);
$check = wp_check_filetype(PathHelper::basename($src), null);
$image_exts = apply_filters('timber/post/image_extensions', [
'jpg',
'jpeg',
'jpe',
'gif',
'png',
'webp',
]);

return in_array($check['ext'], $image_exts);
return wp_get_attachment_image_sizes($this->ID, $size) ?: null;
}
}

0 comments on commit b71a6bd

Please sign in to comment.