From 43893696685aa5c8b0966b482c04fed88ed11f04 Mon Sep 17 00:00:00 2001 From: Gary Pendergast Date: Fri, 14 Dec 2018 04:52:27 +0000 Subject: [PATCH] Scripts: Revert some functions being incorrectly removed in [44163]. git-svn-id: https://develop.svn.wordpress.org/trunk@44164 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/script-loader.php | 71 +++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/src/wp-includes/script-loader.php b/src/wp-includes/script-loader.php index c23f2d7373..48e671b731 100644 --- a/src/wp-includes/script-loader.php +++ b/src/wp-includes/script-loader.php @@ -2406,3 +2406,74 @@ function script_concat_settings() { } } } + +/** + * Handles the enqueueing of block scripts and styles that are common to both + * the editor and the front-end. + * + * @since 5.0.0 + * + * @global WP_Screen $current_screen + */ +function wp_common_block_scripts_and_styles() { + global $current_screen; + + if ( is_admin() && ! $current_screen->is_block_editor() ) { + return; + } + + wp_enqueue_style( 'wp-block-library' ); + + if ( current_theme_supports( 'wp-block-styles' ) ) { + wp_enqueue_style( 'wp-block-library-theme' ); + } + + /** + * Fires after enqueuing block assets for both editor and front-end. + * + * Call `add_action` on any hook before 'wp_enqueue_scripts'. + * + * In the function call you supply, simply use `wp_enqueue_script` and + * `wp_enqueue_style` to add your functionality to the Gutenberg editor. + * + * @since 5.0.0 + */ + do_action( 'enqueue_block_assets' ); +} + +/** + * Enqueues registered block scripts and styles, depending on current rendered + * context (only enqueuing editor scripts while in context of the editor). + * + * @since 5.0.0 + * + * @global WP_Screen $current_screen + */ +function wp_enqueue_registered_block_scripts_and_styles() { + global $current_screen; + + $is_editor = ( is_admin() && $current_screen->is_block_editor() ); + + $block_registry = WP_Block_Type_Registry::get_instance(); + foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) { + // Front-end styles. + if ( ! empty( $block_type->style ) ) { + wp_enqueue_style( $block_type->style ); + } + + // Front-end script. + if ( ! empty( $block_type->script ) ) { + wp_enqueue_script( $block_type->script ); + } + + // Editor styles. + if ( $is_editor && ! empty( $block_type->editor_style ) ) { + wp_enqueue_style( $block_type->editor_style ); + } + + // Editor script. + if ( $is_editor && ! empty( $block_type->editor_script ) ) { + wp_enqueue_script( $block_type->editor_script ); + } + } +}