wppaste
WordPress

WP_Widget_Block

Since
5.8.0
Source
wp-includes/widgets/class-wp-widget-block.php:17
Core class used to implement a Block widget.

Compatibility

WordPress
since 5.8.0
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0).

Hooks and filters fired · 2

Every hook that fires from inside WP_Widget_Block, in the order it appears in the class, grouped by the method that fires it.

Properties · 1

$default_instancearrayprotected
Default instance.

Methods · 6

Source code

class WP_Widget_Block extends WP_Widget { 	/**	 * Default instance.	 *	 * @since 5.8.0	 * @var array	 */	protected $default_instance = array(		'content' => '',	); 	/**	 * Sets up a new Block widget instance.	 *	 * @since 5.8.0	 */	public function __construct() {		$widget_ops  = array(			'classname'                   => 'widget_block',			'description'                 => __( 'A widget containing a block.' ),			'customize_selective_refresh' => true,			'show_instance_in_rest'       => true,		);		$control_ops = array(			'width'  => 400,			'height' => 350,		);		parent::__construct( 'block', __( 'Block' ), $widget_ops, $control_ops ); 		add_filter( 'is_wide_widget_in_customizer', array( $this, 'set_is_wide_widget_in_customizer' ), 10, 2 );	} 	/**	 * Outputs the content for the current Block widget instance.	 *	 * @since 5.8.0	 *	 * @param array $args     Display arguments including 'before_title', 'after_title',	 *                        'before_widget', and 'after_widget'.	 * @param array $instance Settings for the current Block widget instance.	 */	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'];	} 	/**	 * Calculates the classname to use in the block widget's container HTML.	 *	 * Usually this is set to `$this->widget_options['classname']` by	 * dynamic_sidebar(). In this case, however, we want to set the classname	 * dynamically depending on the block contained by this block widget.	 *	 * If a block widget contains a block that has an equivalent legacy widget,	 * we display that legacy widget's class name. This helps with theme	 * backwards compatibility.

Changelog

Introduced in 5.8.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 tag, from src/wp-includes/widgets/class-wp-widget-block.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.