wppaste
WordPress

WP_Widget

Since
2.8.0, 4.4.0
Source
wp-includes/class-wp-widget.php:20
Core base class extended to register widgets.

Description

This class must be extended for each widget, and WP_Widget::widget() must be overridden.

If adding widget options, WP_Widget::update() and WP_Widget::form() should also be overridden.

Compatibility

WordPress
since 4.4.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 · 4

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

Properties · 9

$id_basemixed|stringpublic
Root ID for all widgets of this type.
$namestringpublic
Name for this widget type.
$option_namestringpublic
Option name for this widget type.
$alt_option_namestringpublic
Alt option name for this widget type.
$widget_optionsarraypublic
Option array passed to wp_register_sidebar_widget().
$control_optionsarraypublic
Option array passed to wp_register_widget_control().
$numberbool|intpublic
Unique ID number of the current instance.
$idbool|stringpublic
Unique ID string of the current instance (id_base-number).
$updatedboolpublic
Whether the widget data has been updated.

Methods · 19

Source code

#[AllowDynamicProperties]class WP_Widget { 	/**	 * Root ID for all widgets of this type.	 *	 * @since 2.8.0	 * @var mixed|string	 */	public $id_base; 	/**	 * Name for this widget type.	 *	 * @since 2.8.0	 * @var string	 */	public $name; 	/**	 * Option name for this widget type.	 *	 * @since 2.8.0	 * @var string	 */	public $option_name; 	/**	 * Alt option name for this widget type.	 *	 * @since 2.8.0	 * @var string	 */	public $alt_option_name; 	/**	 * Option array passed to wp_register_sidebar_widget().	 *	 * @since 2.8.0	 * @var array	 */	public $widget_options; 	/**	 * Option array passed to wp_register_widget_control().	 *	 * @since 2.8.0	 * @var array	 */	public $control_options; 	/**	 * Unique ID number of the current instance.	 *	 * @since 2.8.0	 * @var bool|int	 */	public $number = false; 	/**	 * Unique ID string of the current instance (id_base-number).	 *	 * @since 2.8.0	 * @var bool|string	 */	public $id = false; 	/**	 * Whether the widget data has been updated.	 *	 * Set to true when the data is updated after a POST submit - ensures it does	 * not happen twice.	 *	 * @since 2.8.0	 * @var bool	 */	public $updated = false; 	//	// Member functions that must be overridden by subclasses.

Changelog

Introduced in 2.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.

4.4.0
Moved to its own file from wp-includes/widgets.phpfrom the docblock
2.8.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.8.8 tag, from src/wp-includes/class-wp-widget.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.