Skip to content
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

Closed

Conversation

getdave
Copy link

@getdave getdave commented Jan 23, 2024

Syncs changes from

...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.

Copy link

Test using WordPress Playground

The 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

  • The Plugin and Theme Directories cannot be accessed within Playground.
  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

Copy link
Member

@dmsnell dmsnell left a 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!

@getdave
Copy link
Author

getdave commented Jan 24, 2024

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 ) ) {
Copy link
Member

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.

Copy link
Member

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

function str_contains( $haystack, $needle ) {
if ( '' === $needle ) {
return true;
}
return false !== strpos( $haystack, $needle );
}

Copy link
Author

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.

Copy link
Author

Choose a reason for hiding this comment

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

Copy link
Member

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.

Copy link
Author

@getdave getdave Jan 26, 2024

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:

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.

Copy link
Member

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.

@getdave
Copy link
Author

getdave commented Jan 30, 2024

@ocean90 @dmsnell I've now:

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

@youknowriad
Copy link
Contributor

commit in https://core.trac.wordpress.org/changeset/57383

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants