get_block_editor_server_block_settings

函数
get_block_editor_server_block_settings ( No parameters )
返回值
  • (array) An associative array of registered block data.
定义位置
相关方法
get_block_editor_settingsget_default_block_editor_settingsget_block_editor_theme_stylesget_legacy_widget_block_editor_settingswp_get_code_editor_settings
引入
5.0.0
弃用
-

get_block_editor_server_block_settings:此函数返回编辑器的块设置数组,例如默认块名称、是否显示插入器按钮以及其他选项。它不接受任何参数。

为区块编辑器准备服务器注册的区块。

返回一个以区块名称为关键字的注册区块数据的关联数组。数据包括与客户端注册相关的块的属性。

function get_block_editor_server_block_settings() {
	$block_registry = WP_Block_Type_Registry::get_instance();
	$blocks         = array();
	$fields_to_pick = array(
		'api_version'      => 'apiVersion',
		'title'            => 'title',
		'description'      => 'description',
		'icon'             => 'icon',
		'attributes'       => 'attributes',
		'provides_context' => 'providesContext',
		'uses_context'     => 'usesContext',
		'supports'         => 'supports',
		'category'         => 'category',
		'styles'           => 'styles',
		'textdomain'       => 'textdomain',
		'parent'           => 'parent',
		'ancestor'         => 'ancestor',
		'keywords'         => 'keywords',
		'example'          => 'example',
		'variations'       => 'variations',
	);

	foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) {
		foreach ( $fields_to_pick as $field => $key ) {
			if ( ! isset( $block_type->{ $field } ) ) {
				continue;
			}

			if ( ! isset( $blocks[ $block_name ] ) ) {
				$blocks[ $block_name ] = array();
			}

			$blocks[ $block_name ][ $key ] = $block_type->{ $field };
		}
	}

	return $blocks;
}

常见问题

FAQs
查看更多 >