Post Title: Fix empty heading element when post_title is empty but get_the_title returns markup V2#73841
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: @shubh.mittal@rtcamp.com. 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. |
| $title = get_the_title(); | ||
|
|
||
| if ( ! $title ) { | ||
| if ( ! strip_tags( $title ) ) { |
There was a problem hiding this comment.
Left a note regarding using both (! title || ! strip_tags()) checks in the original PR - #70417 (comment).
There was a problem hiding this comment.
@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.
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.
I've been profiling, and with a couple million iterations it scales faster without the first check.
There was a problem hiding this comment.
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.
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