-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Bail out if get_current_screen() returns null. #33261
Bail out if get_current_screen() returns null. #33261
Conversation
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.
Does this need backport to WP 5.8? |
It would be good to backport it, I ran into this issue when trying to patch https://core.trac.wordpress.org/ticket/53429 and had to resort to a somewhat ugly hack (WordPress/wordpress-develop@069d32f) |
This particular callback function is not in WP 5.8. The PHP notice is not thrown in 5.8-RC2. That said, would be worth opening a new Trac ticket to investigate the problem you saw @aristath as there may be a hole in the merged implementation that needs a check like this. |
} | ||
|
||
$current_screen = get_current_screen(); | ||
if ( is_null( $current_screen ) ) { |
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.
Why not check for the instanceof WP_Screen
?
- As this is a plugin, an additional check might be required to ensure the class
WP_Screen
exists. get_current_screen
returnsnull
on failure or an instance ofWP_Screen
on success.
The check here is for the failure state. Using this approach keeps the check positive and simple, while avoiding an additional class_exists
check.
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.
FWIW, you can safely do an instanceof
check with a class that does not exist., https://3v4l.org/X4n64.
Description
In function
gutenberg_widgets_customize_load_block_editor_scripts_and_styles()
on < WordPress 5.8-RC2, a PHP notice is thrown whenget_current_screen()
returnsnull
.This happens because the instance is used to get the
base
property as part of the conditional check.This PR breaks up the conditional checks into guard clauses and then checks if the value returned from
get_current_screen(0
isnull
. If yes, it bails out. If no, then thebase
property is checked.How has this been tested?
Local machine => Notice in debug log before fix. No notice after fix.
Environment:
Note: The PHP notice does not happen with WordPress 5.8-RC2.
Screenshots
Types of changes
null
and bails out if returnedChecklist:
*.native.js
files for terms that need renaming or removal).