-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Fix: PHP 8.1 deprecated warning strpos() #5935
Fix: PHP 8.1 deprecated warning strpos() #5935
Conversation
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
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.
sorry if I missed this one!
Nope. I'm just trying to help things along. Thank you 👍 @youknowriad Can we commit this please? |
@@ -834,7 +834,8 @@ function wp_render_layout_support_flag( $block_content, $block ) { | |||
break; | |||
} | |||
|
|||
if ( false !== strpos( $processor->get_attribute( 'class' ), $inner_block_wrapper_classes ) ) { | |||
$class_attribute = $processor->get_attribute( 'class' ); | |||
if ( is_string( $class_attribute ) && false !== strpos( $class_attribute, $inner_block_wrapper_classes ) ) { |
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.
Looks like you can make use of str_contains()
here.
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.
+1 The polyfill version is available from 5.9. See
wordpress-develop/src/wp-includes/compat.php
Lines 468 to 474 in 6daf853
function str_contains( $haystack, $needle ) { | |
if ( '' === $needle ) { | |
return true; | |
} | |
return false !== strpos( $haystack, $needle ); | |
} |
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.
Note to self: this will now require us to backport the usage of str_contains
to the Gutenberg repo.
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.
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.
thanks for the update. generally I would encourage folks to think about separating the act of bringing over already-merged and accepted code from the act of changing it.
it can make it difficult to deal with when things go wrong because we've wrapped up a styling-preference change with what should otherwise be a somewhat mechanical copy operation.
another way this could have taken place is to create a PR in Gutenberg to update the code where it came from, and then port that change over, so we don't introduce divergence between the repos without a clear audit trail.
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.
That sounds like a better plan. I have:
- Reverted to match the changeset in Fix: PHP 8.1 deprecated warning strpos() gutenberg#56171.
- Updated Layout block supports use
str_contains
gutenberg#58251 to make thestr_contains
change suggested here.
Once this one is merged I will raise a new PR to backport the change from WordPress/gutenberg#58251.
This leaves a clear audit trail and avoid any further confusion.
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.
you're amazing. to be clear, I would have asked to change this PR if I thought it was important enough to reject, so thanks for going above and beyond to split these apart.
mostly I wanted us all to think about these kinds of things and the headaches that can happen when mangling them. "style-only changes" often introduce behavioral bugs and that's never fun in a crisis moment.
This reverts commit abc1865.
So we should be good to go 🤞 Please can this be approved so I can tick it off the backports list. Many thanks in advance 🙇 cc @youknowriad |
Syncs changes from
str_contains
gutenberg#58251...to Core.
Fix for PHP warning in Layout Block Supports.
Trac ticket: https://core.trac.wordpress.org/ticket/60327
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.