-
Notifications
You must be signed in to change notification settings - Fork 4k
/
script-loader.php
109 lines (92 loc) · 3.34 KB
/
script-loader.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
/**
* Updates the script-loader.php file
*
* @package gutenberg
*/
/**
* Removes the actions that output all duotone SVG filter presets.
* WP_Duotone_Gutenberg now handles which SVG filters should be output
* depending on the block content.
*/
remove_action( 'wp_body_open', 'wp_global_styles_render_svg_filters' );
remove_action( 'in_admin_header', 'wp_global_styles_render_svg_filters' );
/**
* Collect the block editor assets that need to be loaded into the editor's iframe.
*
* @since 6.0.0
* @access private
*
* @return array {
* The block editor assets.
*
* @type string|false $styles String containing the HTML for styles.
* @type string|false $scripts String containing the HTML for scripts.
* }
*/
function _gutenberg_get_iframed_editor_assets() {
global $wp_styles, $wp_scripts, $pagenow;
// Keep track of the styles and scripts instance to restore later.
$current_wp_styles = $wp_styles;
$current_wp_scripts = $wp_scripts;
// Create new instances to collect the assets.
$wp_styles = new WP_Styles();
$wp_scripts = new WP_Scripts();
// Register all currently registered styles and scripts. The actions that
// follow enqueue assets, but don't necessarily register them.
$wp_styles->registered = $current_wp_styles->registered;
$wp_scripts->registered = $current_wp_scripts->registered;
// We generally do not need reset styles for the iframed editor.
// However, if it's a classic theme, margins will be added to every block,
// which is reset specifically for list items, so classic themes rely on
// these reset styles.
$wp_styles->done =
wp_theme_has_theme_json() ? array( 'wp-reset-editor-styles' ) : array();
wp_enqueue_script( 'wp-polyfill' );
// Enqueue the `editorStyle` handles for all core block, and dependencies.
wp_enqueue_style( 'wp-edit-blocks' );
if ( 'site-editor.php' === $pagenow ) {
wp_enqueue_style( 'wp-edit-site' );
}
if ( current_theme_supports( 'wp-block-styles' ) ) {
wp_enqueue_style( 'wp-block-library-theme' );
}
// We don't want to load EDITOR scripts in the iframe, only enqueue
// front-end assets for the content.
add_filter( 'should_load_block_editor_scripts_and_styles', '__return_false' );
do_action( 'enqueue_block_assets' );
remove_filter( 'should_load_block_editor_scripts_and_styles', '__return_false' );
$block_registry = WP_Block_Type_Registry::get_instance();
// Additionally, do enqueue `editorStyle` assets for all blocks, which
// contains editor-only styling for blocks (editor content).
foreach ( $block_registry->get_all_registered() as $block_type ) {
if ( isset( $block_type->editor_style_handles ) && is_array( $block_type->editor_style_handles ) ) {
foreach ( $block_type->editor_style_handles as $style_handle ) {
wp_enqueue_style( $style_handle );
}
}
}
ob_start();
wp_print_styles();
wp_print_fonts( true );
$styles = ob_get_clean();
ob_start();
wp_print_head_scripts();
wp_print_footer_scripts();
$scripts = ob_get_clean();
// Restore the original instances.
$wp_styles = $current_wp_styles;
$wp_scripts = $current_wp_scripts;
return array(
'styles' => $styles,
'scripts' => $scripts,
);
}
add_filter(
'block_editor_settings_all',
static function( $settings ) {
// We must override what core is passing now.
$settings['__unstableResolvedAssets'] = _gutenberg_get_iframed_editor_assets();
return $settings;
}
);