W3cubDocs

/WordPress

WP_Widget_Block::widget( array $args, array $instance )

Outputs the content for the current Block widget instance.

Parameters

$argsarrayrequired
Display arguments including 'before_title', 'after_title', 'before_widget', and 'after_widget'.
$instancearrayrequired
Settings for the current Block widget instance.

Source

public function widget( $args, $instance ) {
	$instance = wp_parse_args( $instance, $this->default_instance );

	echo str_replace(
		'widget_block',
		$this->get_dynamic_classname( $instance['content'] ),
		$args['before_widget']
	);

	/**
	 * Filters the content of the Block widget before output.
	 *
	 * @since 5.8.0
	 *
	 * @param string          $content  The widget content.
	 * @param array           $instance Array of settings for the current widget.
	 * @param WP_Widget_Block $widget   Current Block widget instance.
	 */
	echo apply_filters(
		'widget_block_content',
		$instance['content'],
		$instance,
		$this
	);

	echo $args['after_widget'];
}

Hooks

apply_filters( ‘widget_block_content’, string $content, array $instance, WP_Widget_Block $widget )

Filters the content of the Block widget before output.

Changelog

Version Description
5.8.0 Introduced.

© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_widget_block/widget