Make WordPress Core

Changeset 53160


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].

Location:
trunk/src/wp-includes
Files:
4 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' ),
  • trunk/src/wp-includes/default-filters.php

    r53158 r53160  
    592592add_action( 'wp_footer', 'wp_maybe_inline_styles', 1 ); // Run for late-loaded styles in the footer.
    593593
    594 add_action( 'admin_footer-post.php', 'wp_add_iframed_editor_assets_html' );
    595 add_action( 'admin_footer-post-new.php', 'wp_add_iframed_editor_assets_html' );
    596 add_action( 'admin_footer-widgets.php', 'wp_add_iframed_editor_assets_html' );
    597 add_action( 'admin_footer-site-editor.php', 'wp_add_iframed_editor_assets_html' );
    598 
    599594add_action( 'use_block_editor_for_post_type', '_disable_block_editor_for_navigation_post_type', 10, 2 );
    600595add_action( 'edit_form_after_title', '_disable_content_editor_for_navigation_post_type' );
  • trunk/src/wp-includes/deprecated.php

    r53087 r53160  
    43024302                $spacing_support['__experimentalSkipSerialization'];
    43034303}
     4304
     4305/**
     4306 * Inject the block editor assets that need to be loaded into the editor's iframe as an inline script.
     4307 *
     4308 * @since 5.8.0
     4309 * @deprecated 6.0.0
     4310 */
     4311function wp_add_iframed_editor_assets_html() {
     4312        _deprecated_function( __FUNCTION__, '6.0.0' );
     4313}
  • trunk/src/wp-includes/script-loader.php

    r53140 r53160  
    28852885
    28862886/**
    2887  * Inject the block editor assets that need to be loaded into the editor's iframe as an inline script.
    2888  *
    2889  * @since 5.8.0
    2890  *
    2891  * @global string $pagenow The filename of the current screen.
    2892  */
    2893 function wp_add_iframed_editor_assets_html() {
    2894         global $pagenow;
    2895 
    2896         if ( ! wp_should_load_block_editor_scripts_and_styles() ) {
    2897                 return;
    2898         }
    2899 
    2900         $script_handles = array();
    2901         $style_handles  = array(
    2902                 'wp-block-editor',
    2903                 'wp-block-library',
    2904                 'wp-block-library-theme',
    2905                 'wp-edit-blocks',
    2906         );
    2907 
    2908         if ( 'widgets.php' === $pagenow || 'customize.php' === $pagenow ) {
    2909                 $style_handles[] = 'wp-widgets';
    2910                 $style_handles[] = 'wp-edit-widgets';
    2911         }
    2912 
    2913         $block_registry = WP_Block_Type_Registry::get_instance();
    2914 
    2915         foreach ( $block_registry->get_all_registered() as $block_type ) {
    2916                 if ( ! empty( $block_type->style ) ) {
    2917                         $style_handles[] = $block_type->style;
    2918                 }
    2919 
    2920                 if ( ! empty( $block_type->editor_style ) ) {
    2921                         $style_handles[] = $block_type->editor_style;
    2922                 }
    2923 
    2924                 if ( ! empty( $block_type->script ) ) {
    2925                         $script_handles[] = $block_type->script;
    2926                 }
    2927         }
    2928 
    2929         $style_handles = array_unique( $style_handles );
    2930         $done          = wp_styles()->done;
    2931 
    2932         ob_start();
    2933 
    2934         // We do not need reset styles for the iframed editor.
    2935         wp_styles()->done = array( 'wp-reset-editor-styles' );
    2936         wp_styles()->do_items( $style_handles );
    2937         wp_styles()->done = $done;
    2938 
    2939         $styles = ob_get_clean();
    2940 
    2941         $script_handles = array_unique( $script_handles );
    2942         $done           = wp_scripts()->done;
    2943 
    2944         ob_start();
    2945 
    2946         wp_scripts()->done = array();
    2947         wp_scripts()->do_items( $script_handles );
    2948         wp_scripts()->done = $done;
    2949 
    2950         $scripts = ob_get_clean();
    2951 
    2952         $editor_assets = wp_json_encode(
    2953                 array(
    2954                         'styles'  => $styles,
    2955                         'scripts' => $scripts,
    2956                 )
    2957         );
    2958 
    2959         echo "<script>window.__editorAssets = $editor_assets</script>";
    2960 }
    2961 
    2962 /**
    29632887 * Function that enqueues the CSS Custom Properties coming from theme.json.
    29642888 *
Note: See TracChangeset for help on using the changeset viewer.