_wp_get_iframed_editor_assets

函式
_wp_get_iframed_editor_assets ( No parameters )
Access
Private
返回值
  • (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. }
定義位置
相關方法
wp_add_iframed_editor_assets_htmlwp_get_image_editorwp_get_code_editor_settingswp_get_recent_postsget_editor_stylesheets
引入
6.0.0
棄用
-

_wp_get_iframed_editor_assets: 當區塊編輯器在一個iframe中被載入時,這個函式被用來排隊等待它所需要的資產。它載入必要的CSS和JavaScript檔案,以便在一個iframe中執行編輯器。

收集需要載入到編輯器iframe中的區塊編輯器資產。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function _wp_get_iframed_editor_assets() {
global $pagenow;
$script_handles = array();
$style_handles = array(
'wp-block-editor',
'wp-block-library',
'wp-edit-blocks',
);
if ( current_theme_supports( 'wp-block-styles' ) ) {
$style_handles[] = 'wp-block-library-theme';
}
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 ) {
$style_handles = array_merge(
$style_handles,
$block_type->style_handles,
$block_type->editor_style_handles
);
$script_handles = array_merge(
$script_handles,
$block_type->script_handles
);
}
$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,
);
}
function _wp_get_iframed_editor_assets() { global $pagenow; $script_handles = array(); $style_handles = array( 'wp-block-editor', 'wp-block-library', 'wp-edit-blocks', ); if ( current_theme_supports( 'wp-block-styles' ) ) { $style_handles[] = 'wp-block-library-theme'; } 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 ) { $style_handles = array_merge( $style_handles, $block_type->style_handles, $block_type->editor_style_handles ); $script_handles = array_merge( $script_handles, $block_type->script_handles ); } $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, ); }
function _wp_get_iframed_editor_assets() {
	global $pagenow;

	$script_handles = array();
	$style_handles  = array(
		'wp-block-editor',
		'wp-block-library',
		'wp-edit-blocks',
	);

	if ( current_theme_supports( 'wp-block-styles' ) ) {
		$style_handles[] = 'wp-block-library-theme';
	}

	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 ) {
		$style_handles = array_merge(
			$style_handles,
			$block_type->style_handles,
			$block_type->editor_style_handles
		);

		$script_handles = array_merge(
			$script_handles,
			$block_type->script_handles
		);
	}

	$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,
	);
}

常見問題

FAQs
檢視更多 >