Plugin: Account for null return of get_current_screen
#14558
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #14547
This pull request seeks to resolve issues where calling the deprecated functions
is_gutenberg_page
orgutenberg_init
in a non-WP-Admin context may produce fatal errors.For additional context, see #14547 (comment) .
Additional unguarded references to
get_current_screen
exist inlib/widgets.php
. However, these functions are action handlers foradmin_print_styles
, at which point it's considered an assumed guarantee thatget_current_screen
would exist and return a non-null
value (the screen is set immediately prior to the actions firing). This is still a loose guarantee, and it may be advisable to consider introducing guarded conditions all the same (e.g. for handling an unprompted plugin'sdo_action( 'admin_print_styles' );
).Testing instructions:
Place the following file as e.g.
is-gutenberg-page.php
withinwp-content/mu-plugins
. There should be no fatal error when visiting the front of the site.