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.
WP_Widget::form_callback()
- apply_filters( widget_form_callback )filter line 530
- do_action( in_widget_form )action line 553
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
- widget()Echoes the widget content.
- update()Updates a particular instance of a widget.
- form()Outputs the settings update form.
- __construct()PHP5 constructor.
- WP_Widget()PHP4 constructor.
- get_field_name()Constructs name attributes for use in form() fields
- get_field_id()Constructs id attributes for use in WP_Widget::form() fields.
- _register()Register all widget instances of this widget class.
- _set()Sets the internal order number for the widget instance.
- _get_display_callback()Retrieves the widget display callback.
- _get_update_callback()Retrieves the widget update callback.
- _get_form_callback()Retrieves the form callback.
- is_preview()Determines whether the current request is inside the Customizer preview.
- display_callback()Generates the actual widget content (Do NOT override).
- update_callback()Handles changed settings (Do NOT override).
- form_callback()Generates the widget control form (Do NOT override).
- _register_one()Registers an instance of the widget class.
- save_settings()Saves the settings for all instances of the widget class.
- get_settings()Retrieves the settings for all instances of the widget class.
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.
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 7.0.4 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.