render_block_core_legacy_widget()WP 1.0

Renders the 'core/legacy-widget' block.

Хуков нет.

Возвращает

Строку. Rendered block.

Использование

render_block_core_legacy_widget( $attributes );
$attributes(массив) (обязательный)
The block attributes.

Код render_block_core_legacy_widget() WP 6.0.2

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 ( wp_hash( $serialized_instance ) !== $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();
}