From 3a69baa1201c3c1a3e7738205b9c7f62fc7bc9b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Zi=C3=B3=C5=82kowski?= Date: Wed, 13 Apr 2022 09:29:30 +0200 Subject: [PATCH] Plugin: Move the logic for iframed editor to WP 6.0 compat (#40278) --- lib/client-assets.php | 73 ---------------------- lib/compat/wordpress-6.0/client-assets.php | 73 ++++++++++++++++++++++ 2 files changed, 73 insertions(+), 73 deletions(-) diff --git a/lib/client-assets.php b/lib/client-assets.php index b48731fe724f7..116742d925aac 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -446,76 +446,3 @@ function gutenberg_register_packages_styles( $styles ) { $styles->add_data( 'wp-widgets', 'rtl', 'replace' ); } add_action( 'wp_default_styles', 'gutenberg_register_packages_styles' ); - -/** - * Sets the editor styles to be consumed by JS. - */ -function gutenberg_resolve_assets() { - global $pagenow; - - $script_handles = array(); - $style_handles = array( - 'wp-block-editor', - 'wp-block-library', - 'wp-block-library-theme', - 'wp-edit-blocks', - ); - - if ( 'widgets.php' === $pagenow || 'customize.php' === $pagenow ) { - $style_handles[] = 'wp-widgets'; - $style_handles[] = 'wp-edit-widgets'; - } - - $block_registry = WP_Block_Type_Registry::get_instance(); - - foreach ( $block_registry->get_all_registered() as $block_type ) { - if ( ! empty( $block_type->style ) ) { - $style_handles[] = $block_type->style; - } - - if ( ! empty( $block_type->editor_style ) ) { - $style_handles[] = $block_type->editor_style; - } - - if ( ! empty( $block_type->script ) ) { - $script_handles[] = $block_type->script; - } - } - - $style_handles = array_unique( $style_handles ); - $done = wp_styles()->done; - - ob_start(); - - // We do not need reset styles for the iframed editor. - wp_styles()->done = array( 'wp-reset-editor-styles' ); - wp_styles()->do_items( $style_handles ); - wp_styles()->done = $done; - - $styles = ob_get_clean(); - - $script_handles = array_unique( $script_handles ); - $done = wp_scripts()->done; - - ob_start(); - - wp_scripts()->done = array(); - wp_scripts()->do_items( $script_handles ); - wp_scripts()->done = $done; - - $scripts = ob_get_clean(); - - return array( - 'styles' => $styles, - 'scripts' => $scripts, - ); -} - -add_filter( - 'block_editor_settings_all', - function( $settings ) { - // In the future we can allow WP Dependency handles to be passed. - $settings['__unstableResolvedAssets'] = gutenberg_resolve_assets(); - return $settings; - } -); diff --git a/lib/compat/wordpress-6.0/client-assets.php b/lib/compat/wordpress-6.0/client-assets.php index 1d2f76ee34273..77f0593dc8778 100644 --- a/lib/compat/wordpress-6.0/client-assets.php +++ b/lib/compat/wordpress-6.0/client-assets.php @@ -34,3 +34,76 @@ function gutenberg_register_vendor_scripts( $scripts ) { ); } add_action( 'wp_default_scripts', 'gutenberg_register_vendor_scripts' ); + +/** + * Sets the editor styles to be consumed by JS. + */ +function gutenberg_resolve_assets() { + global $pagenow; + + $script_handles = array(); + $style_handles = array( + 'wp-block-editor', + 'wp-block-library', + 'wp-block-library-theme', + 'wp-edit-blocks', + ); + + if ( 'widgets.php' === $pagenow || 'customize.php' === $pagenow ) { + $style_handles[] = 'wp-widgets'; + $style_handles[] = 'wp-edit-widgets'; + } + + $block_registry = WP_Block_Type_Registry::get_instance(); + + foreach ( $block_registry->get_all_registered() as $block_type ) { + if ( ! empty( $block_type->style ) ) { + $style_handles[] = $block_type->style; + } + + if ( ! empty( $block_type->editor_style ) ) { + $style_handles[] = $block_type->editor_style; + } + + if ( ! empty( $block_type->script ) ) { + $script_handles[] = $block_type->script; + } + } + + $style_handles = array_unique( $style_handles ); + $done = wp_styles()->done; + + ob_start(); + + // We do not need reset styles for the iframed editor. + wp_styles()->done = array( 'wp-reset-editor-styles' ); + wp_styles()->do_items( $style_handles ); + wp_styles()->done = $done; + + $styles = ob_get_clean(); + + $script_handles = array_unique( $script_handles ); + $done = wp_scripts()->done; + + ob_start(); + + wp_scripts()->done = array(); + wp_scripts()->do_items( $script_handles ); + wp_scripts()->done = $done; + + $scripts = ob_get_clean(); + + return array( + 'styles' => $styles, + 'scripts' => $scripts, + ); +} + +add_filter( + 'block_editor_settings_all', + function( $settings ) { + // In the future we can allow WP Dependency handles to be passed. + $settings['__unstableResolvedAssets'] = gutenberg_resolve_assets(); + return $settings; + } +);