render_block_core_legacy_widget

函数
render_block_core_legacy_widget ( $attributes )
参数
  • (array) $attributes The block attributes.
    Required:
返回值
  • (string) Rendered block.
定义位置
相关方法
register_block_core_legacy_widgetrender_block_core_widget_grouprender_block_core_imagerender_block_core_archivesrender_block_core_loginout
引入
-
弃用
-

render_block_core_legacy_widget: 这个函数用来渲染WordPress中的传统小工具块。Legacy Widget块允许用户显示他们网站以前的版本或与块编辑器不兼容的插件的Widget: 这个函数负责生成Legacy Widget块的HTML标记。

渲染’core/legacy-widget’区块。

function render_block_core_legacy_widget( $attributes ) {
	global $wp_widget_factory;

	if ( isset( $attributes['id'] ) ) {
		$sidebar_id = wp_find_widgets_sidebar( $attributes['id'] );
		return wp_render_widget( $attributes['id'], $sidebar_id );
	}

	if ( ! isset( $attributes['idBase'] ) ) {
		return '';
	}

	$id_base       = $attributes['idBase'];
	$widget_key    = $wp_widget_factory->get_widget_key( $id_base );
	$widget_object = $wp_widget_factory->get_widget_object( $id_base );

	if ( ! $widget_key || ! $widget_object ) {
		return '';
	}

	if ( isset( $attributes['instance']['encoded'], $attributes['instance']['hash'] ) ) {
		$serialized_instance = base64_decode( $attributes['instance']['encoded'] );
		if ( ! hash_equals( wp_hash( $serialized_instance ), (string) $attributes['instance']['hash'] ) ) {
			return '';
		}
		$instance = unserialize( $serialized_instance );
	} else {
		$instance = array();
	}

	$args = array(
		'widget_id'   => $widget_object->id,
		'widget_name' => $widget_object->name,
	);

	ob_start();
	the_widget( $widget_key, $instance, $args );
	return ob_get_clean();
}

常见问题

FAQs
查看更多 >