Skip to content
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

Plugin: Account for null return of get_current_screen #14558

Merged
merged 1 commit into from
Mar 22, 2019

Conversation

aduth
Copy link
Member

@aduth aduth commented Mar 21, 2019

Fixes #14547

This pull request seeks to resolve issues where calling the deprecated functions is_gutenberg_page or gutenberg_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 in lib/widgets.php. However, these functions are action handlers for admin_print_styles, at which point it's considered an assumed guarantee that get_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's do_action( 'admin_print_styles' );).

Testing instructions:

Place the following file as e.g. is-gutenberg-page.php within wp-content/mu-plugins. There should be no fatal error when visiting the front of the site.

<?php

add_action( 'init', function() {
	is_gutenberg_page();
} );

@aduth aduth added [Type] Bug An existing feature does not function as intended Gutenberg Plugin Issues or PRs related to Gutenberg Plugin management related efforts labels Mar 21, 2019
@aduth aduth mentioned this pull request Mar 21, 2019
Copy link
Contributor

@youknowriad youknowriad 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 fix.

@aduth aduth merged commit 9bcf036 into master Mar 22, 2019
@aduth aduth deleted the fix/get-current-screen-null branch March 22, 2019 18:12
@youknowriad youknowriad added this to the 5.4 (Gutenberg) milestone Mar 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Gutenberg Plugin Issues or PRs related to Gutenberg Plugin management related efforts [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The site is not working
2 participants