处理编辑器和前端共有的块脚本和样式的入队。

原型

wp_common_block_scripts_and_styles()

源文件

路径:wp-includes/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
<?php
...
function wp_common_block_scripts_and_styles() {
	global $current_screen;

	if ( is_admin() && ( $current_screen instanceof WP_Screen ) && ! $current_screen->is_block_editor() ) {
		return;
	}

	wp_enqueue_style( 'wp-block-library' );

	if ( current_theme_supports( 'wp-block-styles' ) ) {
		wp_enqueue_style( 'wp-block-library-theme' );
	}

	/**
 	 * Fires after enqueuing block assets for both editor and front-end.
 	 *
 	 * Call `add_action` on any hook before 'wp_enqueue_scripts'.
 	 *
 	 * In the function call you supply, simply use `wp_enqueue_script` and
 	 * `wp_enqueue_style` to add your functionality to the Gutenberg editor.
 	 *
 	 * @since 5.0.0
 	 */
	  do_action( 'enqueue_block_assets' );
}

...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/wp_common_block_scripts_and_styles/