Make WordPress Core


Ignore:
Timestamp:
04/12/2022 03:59:47 PM (4 years ago)
Author:
gziolo
Message:

Editor: Use block settings to pass assets for the iframed editor

Backports changes applied in Gutenberg in https://github.com/WordPress/gutenberg/pull/37193.

Props zieladam.
See #55505.
Follow-up for [53157].

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/block-editor.php

    r53138 r53160  
    289289
    290290/**
     291 * Collect the block editor assets that need to be loaded into the editor's iframe.
     292 *
     293 * @since 6.0.0
     294 * @access private
     295 *
     296 * @global string $pagenow The filename of the current screen.
     297 *
     298 * @return array The block editor assets: styles and scripts.
     299 */
     300function _wp_get_iframed_editor_assets() {
     301    global $pagenow;
     302
     303    $script_handles = array();
     304    $style_handles  = array(
     305        'wp-block-editor',
     306        'wp-block-library',
     307        'wp-block-library-theme',
     308        'wp-edit-blocks',
     309    );
     310
     311    if ( 'widgets.php' === $pagenow || 'customize.php' === $pagenow ) {
     312        $style_handles[] = 'wp-widgets';
     313        $style_handles[] = 'wp-edit-widgets';
     314    }
     315
     316    $block_registry = WP_Block_Type_Registry::get_instance();
     317
     318    foreach ( $block_registry->get_all_registered() as $block_type ) {
     319        if ( ! empty( $block_type->style ) ) {
     320            $style_handles[] = $block_type->style;
     321        }
     322
     323        if ( ! empty( $block_type->editor_style ) ) {
     324            $style_handles[] = $block_type->editor_style;
     325        }
     326
     327        if ( ! empty( $block_type->script ) ) {
     328            $script_handles[] = $block_type->script;
     329        }
     330    }
     331
     332    $style_handles = array_unique( $style_handles );
     333    $done          = wp_styles()->done;
     334
     335    ob_start();
     336
     337    // We do not need reset styles for the iframed editor.
     338    wp_styles()->done = array( 'wp-reset-editor-styles' );
     339    wp_styles()->do_items( $style_handles );
     340    wp_styles()->done = $done;
     341
     342    $styles = ob_get_clean();
     343
     344    $script_handles = array_unique( $script_handles );
     345    $done           = wp_scripts()->done;
     346
     347    ob_start();
     348
     349    wp_scripts()->done = array();
     350    wp_scripts()->do_items( $script_handles );
     351    wp_scripts()->done = $done;
     352
     353    $scripts = ob_get_clean();
     354
     355    return array(
     356        'styles'  => $styles,
     357        'scripts' => $scripts,
     358    );
     359}
     360
     361/**
    291362 * Returns the contextualized block editor settings for a selected editor context.
    292363 *
     
    395466    }
    396467
    397     $editor_settings['localAutosaveInterval'] = 15;
    398 
     468    $editor_settings['__unstableResolvedAssets']         = _wp_get_iframed_editor_assets();
     469    $editor_settings['localAutosaveInterval']            = 15;
    399470    $editor_settings['__experimentalDiscussionSettings'] = array(
    400471        'commentOrder'        => get_option( 'comment_order' ),
Note: See TracChangeset for help on using the changeset viewer.