-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Post Title: Fix empty heading element when post_title is empty but get_the_title returns markup V2 #73841
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Unlinked AccountsThe following contributors have not linked their GitHub and WordPress.org accounts: @[email protected]. Contributors, please read how to link your accounts to ensure your work is properly credited in WordPress releases. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
ntsekouras
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
| $title = get_the_title(); | ||
|
|
||
| if ( ! $title ) { | ||
| if ( ! strip_tags( $title ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a note regarding using both (! title || ! strip_tags()) checks in the original PR - #70417 (comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Mamaduka technically that is correct.
But this evaluation interruption is only useful when there is actually a complex task behind the second.
Doing a strip_tags of an empty string is barely a function initialization, almost the same time complexity as the first comparison in terms of performance.
So I feel it's unnecessarily redundant, but as you say, technically it's more efficient, so I would go with whatever you prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, it depends on the case. I don't have a strong opinion here; either option is fine with me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been profiling, and with a couple million iterations it scales faster without the first check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is that with an empty string, still gets to php_strip_tags_ex and allocates a buffer with the duplicated empty string. Over 10 million iterations, there is almost a 3x difference in total. It doesn't scale too crazily but is something to be considered.
I've reported this upstream, reporting a possible PR to improve this a little bit.
php/php-src#20675
It's not going to come anytime early, but it could help us leave this simpler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, @SirLouen!
Fixes #56465
This is a continuation of #70417, here you can find full context
Just for some context:
Fix empty heading element when
post_titleis empty butget_the_titlereturns markup by checking for text content after stripping HTML tags.cc @ntsekouras