-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Code Modernization: Avoid checking if a null email address exists in WP_REST_Users_Controller. #1801
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
Code Modernization: Avoid checking if a null email address exists in WP_REST_Users_Controller. #1801
Conversation
…WP_REST_Users_Controller. This fixes a "Deprecated: trim(): Passing null to parameter WordPress#1 ($string) of type string is deprecated" warning on PHP 8.1. PHP has started requiring that built-in method arguments that are not explicitly declared as nullable may no longer be passed null. In this case it seems to make more sense to avoid calling WordPress's own `email_exists()` function with null, as that method is declared as taking only strings and a null email is never going to exist anyway. Trac ticket: https://core.trac.wordpress.org/ticket/53635
hellofromtonya
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.
I'm not seeing a test scenario for a null, '', or invalid email in the existing phpunit tests. Would be good to add these tests as part of this fix.
src/wp-includes/rest-api/endpoints/class-wp-rest-users-controller.php
Outdated
Show resolved
Hide resolved
…ler.php Co-authored-by: Tonya Mork <[email protected]>
|
FYI, you are in fact running into the deprecation this is fixing in your existing tests. See for example https://github.com/WordPress/wordpress-develop/runs/4083354600?check_suite_focus=true#step:20:403 And a test that would try to pass an empty string as an email address won't actually reach this code, as that gets rejected as "invalid email address" during parameter validation. I can still add such a test if you insist, but it wouldn't actually test the code being changed here. |
|
I looked at that failing test before and my assessment at the time was that this is an issue with the way the test is set up, not with the actual code.
|
|
You may want to check again. The problem isn't whether the user has an email address set, it's whether the incoming REST request specifies a value for the 'email' parameter (i.e. to update the email). You should be able to prove that to yourself easily enough: Add something like if ( null === $request['email'] ) return new WP_Error( 'email_is_null', 'Email is null', array( 'status' => '500' ) );just before the |
|
I see that you've closed https://core.trac.wordpress.org/ticket/53635 without addressing the issue this PR fixes. What's the way forward now? |
@anomiex Trac ticket https://core.trac.wordpress.org/ticket/54730 is now open for continuing PHP 8.x compatibility fixes during the 6.0 cycle. I updated the description in this PR to point at the new ticket. |
|
Looks like #2133 will fix this too, by making the called functions no longer object to being passed null. If that gets merged, this can be closed. |
We enabled this back in October 2021 in the hope that WordPress Core would quickly make progress on their own PHP 8.1 compatibility project. That has not at all been born out, four months later they still need to update their copy-pasted version of their own requests library and still need to fix another random deprecation warning despite [a short PR][1] existing. GitHub's handling for expected-failing tests [is lacking][2], so having a test, even one flagged experimental, failing long term causes some other issues. At this point, let's just disable the test until one or the other makes some progress. [1]: WordPress/wordpress-develop#1801 [2]: https://github.com/actions/toolkit/issues/399
We enabled this back in October 2021 in the hope that WordPress Core would quickly make progress on their own PHP 8.1 compatibility project. That has not at all been born out, four months later they still need to update their copy-pasted version of their own requests library and still need to fix another random deprecation warning despite [a short PR][1] existing. GitHub's handling for expected-failing tests [is lacking][2], so having a test, even one flagged experimental, failing long term causes some other issues. At this point, let's just disable the test until one or the other makes some progress. [1]: WordPress/wordpress-develop#1801 [2]: https://github.com/actions/toolkit/issues/399
We enabled this back in October 2021 in the hope that WordPress Core would quickly make progress on their own PHP 8.1 compatibility project. That has not at all been born out, four months later they still need to update their copy-pasted version of their own requests library and still need to fix another random deprecation warning despite [a short PR][1] existing. GitHub's handling for expected-failing tests [is lacking][2], so having a test, even one flagged experimental, failing long term causes some other issues. At this point, let's just disable the test until one or the other makes some progress. [1]: WordPress/wordpress-develop#1801 [2]: https://github.com/actions/toolkit/issues/399 Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/1841622621
We enabled this back in October 2021 in the hope that WordPress Core would quickly make progress on their own PHP 8.1 compatibility project. That has not at all been born out, four months later they still need to update their copy-pasted version of their own requests library and still need to fix another random deprecation warning despite [a short PR][1] existing. GitHub's handling for expected-failing tests [is lacking][2], so having a test, even one flagged experimental, failing long term causes some other issues. At this point, let's just disable the test until one or the other makes some progress. [1]: WordPress/wordpress-develop#1801 [2]: https://github.com/actions/toolkit/issues/399 Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/1841622621
We enabled this back in October 2021 in the hope that WordPress Core would quickly make progress on their own PHP 8.1 compatibility project. That has not at all been born out, four months later they still need to update their copy-pasted version of their own requests library and still need to fix another random deprecation warning despite [a short PR][1] existing. GitHub's handling for expected-failing tests [is lacking][2], so having a test, even one flagged experimental, failing long term causes some other issues. At this point, let's just disable the test until one or the other makes some progress. [1]: WordPress/wordpress-develop#1801 [2]: https://github.com/actions/toolkit/issues/399 Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/1841622621
We enabled this back in October 2021 in the hope that WordPress Core would quickly make progress on their own PHP 8.1 compatibility project. That has not at all been born out, four months later they still need to update their copy-pasted version of their own requests library and still need to fix another random deprecation warning despite [a short PR][1] existing. GitHub's handling for expected-failing tests [is lacking][2], so having a test, even one flagged experimental, failing long term causes some other issues. At this point, let's just disable the test until one or the other makes some progress. [1]: WordPress/wordpress-develop#1801 [2]: https://github.com/actions/toolkit/issues/399 Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/1841622621
We enabled this back in October 2021 in the hope that WordPress Core would quickly make progress on their own PHP 8.1 compatibility project. That has not at all been born out, four months later they still need to update their copy-pasted version of their own requests library and still need to fix another random deprecation warning despite [a short PR][1] existing. GitHub's handling for expected-failing tests [is lacking][2], so having a test, even one flagged experimental, failing long term causes some other issues. At this point, let's just disable the test until one or the other makes some progress. [1]: WordPress/wordpress-develop#1801 [2]: https://github.com/actions/toolkit/issues/399 Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/1841622621
Once #2133 gets merged, then yes, it will resolve this PR's deprecation notice without further changes. Plus #2133 resolves the issue at the lower level, i.e. where the deprecation notice is triggered. I think overall this PR can be closed in favor of #2133. Note: There's an improvement opportunity, though out of scope for the purpose of this PR:
|
This fixes a "Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated" warning on PHP 8.1.
PHP has started requiring that built-in method arguments that are not explicitly declared as nullable may no longer be passed null. In this case it seems to make more sense to avoid calling WordPress's own
email_exists()function with null, as that method is declared as taking only strings and a null email is never going to exist anyway.Trac ticket: https://core.trac.wordpress.org/ticket/54730
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.