Make WordPress Core

Changeset 44164


Ignore:
Timestamp:
12/14/2018 04:52:27 AM (8 years ago)
Author:
pento
Message:

Scripts: Revert some functions being incorrectly removed in [44163].

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/script-loader.php

    r44163 r44164  
    24072407        }
    24082408}
     2409
     2410/**
     2411 * Handles the enqueueing of block scripts and styles that are common to both
     2412 * the editor and the front-end.
     2413 *
     2414 * @since 5.0.0
     2415 *
     2416 * @global WP_Screen $current_screen
     2417 */
     2418function wp_common_block_scripts_and_styles() {
     2419        global $current_screen;
     2420
     2421        if ( is_admin() && ! $current_screen->is_block_editor() ) {
     2422                return;
     2423        }
     2424
     2425        wp_enqueue_style( 'wp-block-library' );
     2426
     2427        if ( current_theme_supports( 'wp-block-styles' ) ) {
     2428                wp_enqueue_style( 'wp-block-library-theme' );
     2429        }
     2430
     2431        /**
     2432         * Fires after enqueuing block assets for both editor and front-end.
     2433         *
     2434         * Call `add_action` on any hook before 'wp_enqueue_scripts'.
     2435         *
     2436         * In the function call you supply, simply use `wp_enqueue_script` and
     2437         * `wp_enqueue_style` to add your functionality to the Gutenberg editor.
     2438         *
     2439         * @since 5.0.0
     2440         */
     2441          do_action( 'enqueue_block_assets' );
     2442}
     2443
     2444/**
     2445 * Enqueues registered block scripts and styles, depending on current rendered
     2446 * context (only enqueuing editor scripts while in context of the editor).
     2447 *
     2448 * @since 5.0.0
     2449 *
     2450 * @global WP_Screen $current_screen
     2451 */
     2452function wp_enqueue_registered_block_scripts_and_styles() {
     2453        global $current_screen;
     2454
     2455        $is_editor = ( is_admin() && $current_screen->is_block_editor() );
     2456
     2457        $block_registry = WP_Block_Type_Registry::get_instance();
     2458        foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) {
     2459                // Front-end styles.
     2460                if ( ! empty( $block_type->style ) ) {
     2461                        wp_enqueue_style( $block_type->style );
     2462                }
     2463
     2464                // Front-end script.
     2465                if ( ! empty( $block_type->script ) ) {
     2466                        wp_enqueue_script( $block_type->script );
     2467                }
     2468
     2469                // Editor styles.
     2470                if ( $is_editor && ! empty( $block_type->editor_style ) ) {
     2471                        wp_enqueue_style( $block_type->editor_style );
     2472                }
     2473
     2474                // Editor script.
     2475                if ( $is_editor && ! empty( $block_type->editor_script ) ) {
     2476                        wp_enqueue_script( $block_type->editor_script );
     2477                }
     2478        }
     2479}
Note: See TracChangeset for help on using the changeset viewer.