Skip to content

Update script-loader.php#3163

Closed
kbiegert wants to merge 2 commits intoWordPress:trunkfrom
kbiegert:patch-1
Closed

Update script-loader.php#3163
kbiegert wants to merge 2 commits intoWordPress:trunkfrom
kbiegert:patch-1

Conversation

@kbiegert
Copy link

@kbiegert kbiegert commented Aug 31, 2022

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.

Prevent null pointer.
@github-actions
Copy link

Hi @kbiegert! 👋

Thank you for your contribution to WordPress! 💖

It looks like this is your first pull request to wordpress-develop. Here are a few things to be aware of that may help you out!

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,
The WordPress Project

Copy link
Contributor

@costdev costdev left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @kbiegert! I've left one small suggestion.

Can you also update the PR's description to include a link to the Trac ticket for this patch? Thanks!

Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com>
Copy link
Contributor

@costdev costdev left a comment

Choose a reason for hiding this comment

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

Thanks for the quick update @kbiegert! Just a couple more suggestions 🙂

Comment on lines +2407 to 2408
get_current_screen() !== null &&
! get_current_screen()->is_block_editor()
Copy link
Contributor

@costdev costdev Sep 1, 2022

Choose a reason for hiding this comment

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

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Member

Choose a reason for hiding this comment

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

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

Copy link
Contributor

Choose a reason for hiding this comment

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

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:

As-is:
image

With new condition:
image

Copy link
Member

Choose a reason for hiding this comment

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

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.

@kbiegert kbiegert closed this by deleting the head repository Mar 23, 2023
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.

3 participants