函数文档

get_legacy_widget_block_editor_settings()

💡 云策文档标注

概述

get_legacy_widget_block_editor_settings() 函数返回用于 Legacy Widget 块的块编辑器设置,该块默认未注册。它主要提供一个数组,包含通过过滤器控制的隐藏小部件类型列表。

关键要点

  • 函数返回一个数组,用于 get_block_editor_settings() 以配置 Legacy Widget 块。
  • 核心设置是 'widget_types_to_hide_from_legacy_widget_block' 过滤器,允许开发者自定义哪些小部件类型不应在 Legacy Widget 块中显示。
  • 默认隐藏的小部件类型包括 'pages'、'calendar'、'archives' 等常见小部件。

代码示例

function get_legacy_widget_block_editor_settings() {
    $editor_settings = array();

    $editor_settings['widgetTypesToHideFromLegacyWidgetBlock'] = apply_filters(
        'widget_types_to_hide_from_legacy_widget_block',
        array(
            'pages',
            'calendar',
            'archives',
            'media_audio',
            'media_image',
            'media_gallery',
            'media_video',
            'search',
            'text',
            'categories',
            'recent-posts',
            'recent-comments',
            'rss',
            'tag_cloud',
            'custom_html',
            'block',
        )
    );

    return $editor_settings;
}

注意事项

  • 此函数自 WordPress 5.8.0 版本引入。
  • 通过 'widget_types_to_hide_from_legacy_widget_block' 过滤器,开发者可以修改隐藏的小部件类型列表,返回空数组将使所有小部件可用。

📄 原文内容

Returns the block editor settings needed to use the Legacy Widget block which is not registered by default.

Return

array Settings to be used with get_block_editor_settings() .

Source

function get_legacy_widget_block_editor_settings() {
	$editor_settings = array();

	/**
	 * Filters the list of widget-type IDs that should **not** be offered by the
	 * Legacy Widget block.
	 *
	 * Returning an empty array will make all widgets available.
	 *
	 * @since 5.8.0
	 *
	 * @param string[] $widgets An array of excluded widget-type IDs.
	 */
	$editor_settings['widgetTypesToHideFromLegacyWidgetBlock'] = apply_filters(
		'widget_types_to_hide_from_legacy_widget_block',
		array(
			'pages',
			'calendar',
			'archives',
			'media_audio',
			'media_image',
			'media_gallery',
			'media_video',
			'search',
			'text',
			'categories',
			'recent-posts',
			'recent-comments',
			'rss',
			'tag_cloud',
			'custom_html',
			'block',
		)
	);

	return $editor_settings;
}

Hooks

apply_filters( ‘widget_types_to_hide_from_legacy_widget_block’, string[] $widgets )

Filters the list of widget-type IDs that should **not** be offered by the Legacy Widget block.

Changelog

Version Description
5.8.0 Introduced.