From 3b41668b446b5a917964f933163967f34b67abfe Mon Sep 17 00:00:00 2001 From: LyNguyen Date: Sat, 27 Jan 2024 06:58:41 +0700 Subject: [PATCH] Check empty attachment, remvove check type WP_Post --- src/ImagesAlt.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ImagesAlt.php b/src/ImagesAlt.php index 4b11ab08..9407f3aa 100644 --- a/src/ImagesAlt.php +++ b/src/ImagesAlt.php @@ -19,7 +19,11 @@ public function setup() { add_filter( 'get_avatar', [ $this, 'add_avatar_alt' ], 10, 5 ); } - public function add_missing_alt_attribute( array $attributes, WP_Post $attachment ): array { + public function add_missing_alt_attribute( array $attributes, $attachment ): array { + if ( empty( $attachment ) ) { + return $attributes; + } + $attributes['alt'] = $attributes['alt'] ?: $this->normalize( $attachment->post_title ); return $attributes; }