From eeb5289df187debd5d5fdd0876e5f6ba47c7fb9d Mon Sep 17 00:00:00 2001 From: YvetteNikolov Date: Tue, 30 Jun 2026 11:34:46 +0200 Subject: [PATCH 1/2] feat: add accessible iframe title to embed blocks --- src/Gutenberg.php | 66 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/src/Gutenberg.php b/src/Gutenberg.php index d7862ea..a28ec85 100644 --- a/src/Gutenberg.php +++ b/src/Gutenberg.php @@ -120,4 +120,70 @@ public function addGroupColumnCountClass(string $blockContent, array $block): st return $processor->get_updated_html() ?: $blockContent; } + + /** + * Adds a descriptive title to embed iframes for accessibility - "YouTube video: ..." + * Embeds that render no iframe (Twitter, Instagram, ...) are skipped. + */ + #[Filter('render_block_core/embed')] + public function addEmbedIframeTitle(string $blockContent, array $block): string + { + $providerSlug = $block['attrs']['providerNameSlug'] ?? ''; + + if (! is_string($providerSlug) || '' === $providerSlug) { + return $blockContent; + } + + $label = $this->embedProviderLabel($providerSlug); + + $type = $block['attrs']['type'] ?? ''; + if (is_string($type) && in_array($type, ['video', 'audio'], true)) { + $label = sprintf('%s %s', $label, $type); + } + + $processor = new \WP_HTML_Tag_Processor($blockContent); + + $updated = false; + while ($processor->next_tag('iframe')) { + $existingTitle = $processor->get_attribute('title'); + $existingTitle = is_string($existingTitle) ? trim($existingTitle) : ''; + + // Skip if label is already applied + if ('' !== $existingTitle && str_starts_with($existingTitle, $label)) { + continue; + } + + $title = '' !== $existingTitle + ? sprintf('%s: %s', $label, $existingTitle) + : $label; + + $processor->set_attribute('title', $title); + $updated = true; + } + + if (! $updated) { + return $blockContent; + } + + return $processor->get_updated_html() ?: $blockContent; + } + + private function embedProviderLabel(string $slug): string + { + $names = [ + 'youtube' => 'YouTube', + 'vimeo' => 'Vimeo', + 'dailymotion' => 'Dailymotion', + 'ted' => 'TED', + 'videopress' => 'VideoPress', + 'wordpress-tv' => 'WordPress.tv', + 'soundcloud' => 'SoundCloud', + 'spotify' => 'Spotify', + 'flickr' => 'Flickr', + 'animoto' => 'Animoto', + 'kickstarter' => 'Kickstarter', + ]; + + return $names[$slug] ?? ucwords(str_replace('-', ' ', $slug)); + } } From adf29b31c3be0a200f990ecc27d843ce64b50757 Mon Sep 17 00:00:00 2001 From: Yvette Nikolov <48315669+YvetteNikolov@users.noreply.github.com> Date: Tue, 30 Jun 2026 11:46:28 +0200 Subject: [PATCH 2/2] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/Gutenberg.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Gutenberg.php b/src/Gutenberg.php index a28ec85..f922b87 100644 --- a/src/Gutenberg.php +++ b/src/Gutenberg.php @@ -144,7 +144,7 @@ public function addEmbedIframeTitle(string $blockContent, array $block): string $processor = new \WP_HTML_Tag_Processor($blockContent); $updated = false; - while ($processor->next_tag('iframe')) { + while ($processor->next_tag(['tag_name' => 'iframe'])) { $existingTitle = $processor->get_attribute('title'); $existingTitle = is_string($existingTitle) ? trim($existingTitle) : '';