根据当前呈现的上下文排列已注册的块脚本和样式(仅在编辑器的上下文中排队编辑器脚本)。

原型

wp_enqueue_registered_block_scripts_and_styles()

源文件

路径:wp-includes/script-loader.php

<?php
...
function wp_enqueue_registered_block_scripts_and_styles() {
	global $current_screen;
	$is_editor = ( ( $current_screen instanceof WP_Screen ) && $current_screen->is_block_editor() );
	$block_registry = WP_Block_Type_Registry::get_instance();
	foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) {
		// Front-end styles.
		if ( ! empty( $block_type->style ) ) {
			wp_enqueue_style( $block_type->style );
		}
		// Front-end script.
		if ( ! empty( $block_type->script ) ) {
			wp_enqueue_script( $block_type->script );
		}
		// Editor styles.
		if ( $is_editor && ! empty( $block_type->editor_style ) ) {
			wp_enqueue_style( $block_type->editor_style );
		}
		// Editor script.
		if ( $is_editor && ! empty( $block_type->editor_script ) ) {
			wp_enqueue_script( $block_type->editor_script );
		}
	}
}
...
?>

其他

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