Update script-loader.php#3163
Update script-loader.php#3163kbiegert wants to merge 2 commits intoWordPress:trunkfrom kbiegert:patch-1
Conversation
Prevent null pointer.
|
Hi @kbiegert! 👋 Thank you for your contribution to WordPress! 💖 It looks like this is your first pull request to No one monitors this repository for new pull requests. Pull requests must be attached to a Trac ticket to be considered for inclusion in WordPress Core. To attach a pull request to a Trac ticket, please include the ticket's full URL in your pull request description. Pull requests are never merged on GitHub. The WordPress codebase continues to be managed through the SVN repository that this GitHub repository mirrors. Please feel free to open pull requests to work on any contribution you are making. More information about how GitHub pull requests can be used to contribute to WordPress can be found in this blog post. Please include automated tests. Including tests in your pull request is one way to help your patch be considered faster. To learn about WordPress' test suites, visit the Automated Testing page in the handbook. If you have not had a chance, please review the Contribute with Code page in the WordPress Core Handbook. The Developer Hub also documents the various coding standards that are followed:
Thank you, |
Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com>
| get_current_screen() !== null && | ||
| ! get_current_screen()->is_block_editor() |
There was a problem hiding this comment.
Rather than call get_current_screen() twice, can we add global $current_screen; at the top of the function (above the multiline comment, with a line break), and have both of these conditions use the $current_screen variable instead? The docblock for this function will also need to have a @global tag added:
* @since 5.9.1
*
* @global WP_Screen $current_screen WordPress current screen object.
*/
Also, can we replace the new condition with $current_screen instanceof WP_Screen? This will ensure that it's a WP_Screen object before attempting to call the ::is_block_editor() method in the last condition.
There was a problem hiding this comment.
Actually, hold off on the above suggestion for now. Pinging @SergeyBiryukov for a second opinion on this.
Sergey, some files in Core have multiple calls to get_current_screen(). Normally, we'd avoid multiple function calls. Is this something we should avoid here, or is this an exception?
There was a problem hiding this comment.
Looking at the contents of the get_current_screen() function, @costdev's suggestions make sense to me.
I'd also would like to see a test covering the originally reported issue (throwing an error on PHP 8.1 without the fix and passing with the fix).
There was a problem hiding this comment.
Regarding the test: The function relies on is_admin(), which, based on its source will require WP_ADMIN to be defined in order to test this issue and fix.
WP_ADMIN isn't defined in the test suite, and doing so in this test would impact other tests (including for this function). Not sure how to proceed with that.
That said, here's two screenshots:
There was a problem hiding this comment.
Yes, you got a point about the define(). There are ways around it (run in separate process, run as separate test suite), but those are outside the scope of this particular fix.


Prevent null pointer.
Trac ticket: ticket 56482
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.