Skip to content

fix: strip images from key event titles#785

Merged
GaryJones merged 1 commit intoAutomattic:developfrom
cnaples79:fix-key-event-title
Jan 13, 2026
Merged

fix: strip images from key event titles#785
GaryJones merged 1 commit intoAutomattic:developfrom
cnaples79:fix-key-event-title

Conversation

@cnaples79
Copy link
Contributor

@cnaples79 cnaples79 commented Dec 29, 2025

Summary

Fixes the key event title formatting to properly strip HTML tags, preventing images and other content from leaking into key event headings.

Problem

The previous code used wp_strip_all_tags() with what appeared to be an allowed tags parameter:

wp_strip_all_tags( $content, '<strong><em><span><img>' );

However, wp_strip_all_tags() doesn't support an allowlist - its second parameter is $remove_breaks (boolean). The string was coerced to true, so all tags were stripped anyway, but not intentionally.

Solution

Use wp_strip_all_tags() without parameters to produce clean plain text titles:

wp_strip_all_tags( $content );

Key event titles in the widget are now guaranteed to be plain text.

Test plan

  • Create a liveblog entry starting with an image, mark as key event
  • Verify the key events widget shows text content, not the image

Fixes #464

🤖 Updated with Claude Code

@cnaples79 cnaples79 requested a review from a team as a code owner December 29, 2025 23:19
@GaryJones GaryJones added the type: bug Something isn't working label Dec 30, 2025
Copy link
Contributor

@GaryJones GaryJones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tackling #464! The fix intention is correct, but there's an underlying bug in the existing code that should be addressed:

wp_strip_all_tags() doesn't support an allowlist - its second parameter is just a boolean for $remove_breaks:

wp_strip_all_tags( string $text, bool $remove_breaks = false ): string

The current code passes a string like '<strong><em><span>' which PHP coerces to true, so it just strips all tags AND removes line breaks. The formatting tags were never actually preserved.

Suggested fix - use PHP's native strip_tags() which does support an allowlist:

// Before (broken)
$content = wp_strip_all_tags( $content, '<strong></strong><em></em><span></span><img>' );

// After (correct)
$content = strip_tags( $content, '<strong><em><span>' );

Or if we actually want plain text with no formatting in key event titles:

$content = wp_strip_all_tags( $content );

Which approach would you prefer?

@GaryJones GaryJones added the status: awaiting feedback Awaiting feedback from reporter label Dec 30, 2025
@GaryJones GaryJones added this to the 1.10.0 milestone Dec 30, 2025
@GaryJones GaryJones marked this pull request as draft December 31, 2025 17:25
@GaryJones GaryJones modified the milestones: 1.10.0, Next 1.x Jan 6, 2026
@GaryJones GaryJones force-pushed the fix-key-event-title branch from d254e92 to ff04b35 Compare January 13, 2026 19:38
@GaryJones GaryJones marked this pull request as ready for review January 13, 2026 19:38
The previous code attempted to use wp_strip_all_tags() with an allowed
tags parameter, but this function doesn't support that - its second
parameter is $remove_breaks (boolean). The string was coerced to true,
so all tags were stripped anyway, but not intentionally.

This fix properly uses wp_strip_all_tags() without parameters to
produce clean plain text titles for the key events widget. Images
and other HTML content no longer leak into key event headings.

Fixes Automattic#464

Co-Authored-By: cnaples79 <cnaples79@users.noreply.github.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@GaryJones GaryJones force-pushed the fix-key-event-title branch from ff04b35 to 59aab6e Compare January 13, 2026 19:39
@GaryJones GaryJones merged commit 93c9619 into Automattic:develop Jan 13, 2026
8 checks passed
@GaryJones GaryJones mentioned this pull request Jan 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: awaiting feedback Awaiting feedback from reporter type: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Key events title uses anything

2 participants