fix: strip images from key event titles#785
Merged
GaryJones merged 1 commit intoAutomattic:developfrom Jan 13, 2026
Merged
Conversation
GaryJones
reviewed
Dec 30, 2025
Contributor
GaryJones
left a comment
There was a problem hiding this comment.
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 ): stringThe 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?
d254e92 to
ff04b35
Compare
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>
ff04b35 to
59aab6e
Compare
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:However,
wp_strip_all_tags()doesn't support an allowlist - its second parameter is$remove_breaks(boolean). The string was coerced totrue, so all tags were stripped anyway, but not intentionally.Solution
Use
wp_strip_all_tags()without parameters to produce clean plain text titles:Key event titles in the widget are now guaranteed to be plain text.
Test plan
Fixes #464
🤖 Updated with Claude Code