Editor: Only call should_load_block_editor_scripts_and_styles on admin screens

Do not call the should_load_block_editor_scripts_and_styles filter on non-admin
screens. This makes it less likely that one will accidentally call
get_current_screen() when it doesn't exist.

Follow-up to [49080].
Props noahtallen.
See #51330.


git-svn-id: https://develop.svn.wordpress.org/trunk@49102 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Robert Anderson 2020-10-08 01:19:10 +00:00
parent 9c50d3dda5
commit b7b1584139

View File

@ -2185,7 +2185,7 @@ function script_concat_settings() {
* @global WP_Screen $current_screen WordPress current screen object. * @global WP_Screen $current_screen WordPress current screen object.
*/ */
function wp_common_block_scripts_and_styles() { function wp_common_block_scripts_and_styles() {
if ( is_admin() && ! wp_should_load_block_editor_scripts_and_styles() ) { if ( ! wp_should_load_block_editor_scripts_and_styles() ) {
return; return;
} }
@ -2219,11 +2219,15 @@ function wp_common_block_scripts_and_styles() {
function wp_should_load_block_editor_scripts_and_styles() { function wp_should_load_block_editor_scripts_and_styles() {
global $current_screen; global $current_screen;
if ( ! is_admin() ) {
return false;
}
$is_block_editor_screen = ( $current_screen instanceof WP_Screen ) && $current_screen->is_block_editor(); $is_block_editor_screen = ( $current_screen instanceof WP_Screen ) && $current_screen->is_block_editor();
/** /**
* Filters the flag that decides whether or not block editor scripts and * Filters the flag that decides whether or not block editor scripts and
* styles are going to be enqueued on the current screen. * styles are going to be enqueued on the current admin screen.
* *
* @since 5.6.0 * @since 5.6.0
* *