diff --git a/docs/v2/upgrade-guides/2.0.md b/docs/v2/upgrade-guides/2.0.md index 53ac3ca97..8ae2cb1c1 100644 --- a/docs/v2/upgrade-guides/2.0.md +++ b/docs/v2/upgrade-guides/2.0.md @@ -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 diff --git a/src/Image.php b/src/Image.php index e1688853e..8f17091e7 100644 --- a/src/Image.php +++ b/src/Image.php @@ -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]; @@ -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; } /** @@ -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; } }