Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
Add availability checks to widget related code #15983
This PR adds availability checks for the function get_current_screen and for the globals wp_widget_factory, wp_registered_widgets.
The function get_current_screen should only be called in admin pages, but according to the docs, we may have admin pages without the function so I think a check should be added. For example, I guess it may be possible to have an admin page with admin_footer but without the function defined.
Regarding the globals wp_widget_factory, wp_registered_widgets used in gutenberg_get_legacy_widget_settings function, the function is called as part of the filter block_editor_settings, I guess the filter may be executed in a situation where the widget globals are not initialized e.g: in a custom plugin page with a custom block editor. I think it is better to check the availability of the globals. If the globals are not available we will not pass available legacy widgets to the front end.
How has this been tested?
I verified there are no noticeable changes to the way legacy widgets and block editor widget screen works.