wpseek.com
A WordPress-centric search engine for devs and theme authors



render_block_core_legacy_widget › WordPress Function

Sincen/a
Deprecatedn/a
render_block_core_legacy_widget ( $attributes )
Parameters:
  • (array) $attributes The block attributes.
    Required: Yes
Returns:
  • (string) Rendered block.
Defined at:
Codex:

Renders the 'core/legacy-widget' block.



Source

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 '';
	}

	if ( method_exists( $wp_widget_factory, 'get_widget_object' ) ) {
		$widget_object = $wp_widget_factory->get_widget_object( $attributes['idBase'] );
	} else {
		$widget_object = gutenberg_get_widget_object( $attributes['idBase'] );
	}

	if ( ! $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();
	}

	ob_start();
	the_widget( get_class( $widget_object ), $instance );
	return ob_get_clean();
}