Core base class extended to register widgets.
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.
| package | Akismet |
|---|---|
| inherited_from | \WP_Widget |
WP_Widget(string $id_base, string $name, array $widget_options= array(), array $control_options= array())
| since | 2.8.0 |
|---|---|
| see |
stringOptional Base ID for the widget, lowercase and unique. If left empty, a portion of the widget's class name will be used Has to be unique.
stringName for the widget displayed on the configuration page.
arrayOptional. Widget options. See wp_register_sidebar_widget() for information on accepted arguments. Default empty array.
arrayOptional. Widget control options. See wp_register_widget_control() for information on accepted arguments. Default empty array.
__construct()
| inherited_from | \WP_Widget::__construct() |
|---|
__construct(string $id_base, string $name, array $widget_options= array(), array $control_options= array())
| since | 2.8.0 |
|---|
stringOptional Base ID for the widget, lowercase and unique. If left empty, a portion of the widget's class name will be used Has to be unique.
stringName for the widget displayed on the configuration page.
arrayOptional. Widget options. See wp_register_sidebar_widget() for information on accepted arguments. Default empty array.
arrayOptional. Widget control options. See wp_register_widget_control() for information on accepted arguments. Default empty array.
_get_display_callback() : callable
| since | 2.8.0 |
|---|
callableDisplay callback._get_form_callback() : callable
| since | 2.8.0 |
|---|
callableForm callback._get_update_callback() : callable
| since | 2.8.0 |
|---|
callableUpdate callback._register()
| since | 2.8.0 |
|---|
_register_one(integer $number = -1)
| since | 2.8.0 |
|---|
integerOptional. The unique order number of this widget instance compared to other instances of the same class. Default -1.
_set(integer $number)
| since | 2.8.0 |
|---|
integerThe unique order number of this widget instance compared to other instances of the same class.
css()
display_callback(array $args, integer|array $widget_args = 1)
Finds the instance and calls WP_Widget::widget().
| since | 2.8.0 |
|---|
arrayDisplay arguments. See WP_Widget::widget() for information on accepted arguments.
integerarray{ Optional. Internal order number of the widget instance, or array of multi-widget arguments. Default 1.
@type int $number Number increment used for multiples of the same widget.
}
form(array $instance)
| inherited_from | \WP_Widget::form() |
|---|
form(array $instance) : string
| since | 2.8.0 |
|---|
arrayCurrent settings.
stringDefault return is 'noform'.form_callback(integer|array $widget_args = 1) : string | null
| since | 2.8.0 |
|---|
integerarray{ Optional. Internal order number of the widget instance, or array of multi-widget arguments. Default 1.
@type int $number Number increment used for multiples of the same widget.
}
stringnull
get_field_id(string $field_name) : string
This function should be used in form() methods to create id attributes for fields to be saved by WP_Widget::update().
| since | 2.8.0 |
|---|---|
| since | 4.4.0 Array format field IDs are now accepted. |
stringField name.
stringID attribute for `$field_name`.get_field_name(string $field_name) : string
This function should be used in form() methods to create name attributes for fields to be saved by update()
| since | 2.8.0 |
|---|---|
| since | 4.4.0 Array format field names are now accepted. |
stringField name
stringName attribute for $field_nameget_settings() : array
| since | 2.8.0 |
|---|
arrayMulti-dimensional array of widget instance settings.is_preview() : boolean
If true -- the current request is inside the Customizer preview, then the object cache gets suspended and widgets should check this to decide whether they should store anything persistently to the object cache, to transients, or anywhere else.
| since | 3.9.0 |
|---|---|
| global | WP_Customize_Manager $wp_customize |
booleanTrue if within the Customizer preview, false if not.save_settings(array $settings)
| since | 2.8.0 |
|---|
arrayMulti-dimensional array of widget instance settings.
update(array $new_instance, array $old_instance)
This function should check that $new_instance is set correctly. The newly-calculated
value of $instance should be returned. If false is returned, the instance won't be
saved/updated.
| inherited_from | \WP_Widget::update() |
|---|
update(array $new_instance, array $old_instance) : array
This function should check that $new_instance is set correctly. The newly-calculated
value of $instance should be returned. If false is returned, the instance won't be
saved/updated.
| since | 2.8.0 |
|---|
arrayNew settings for this instance as input by the user via WP_Widget::form().
arrayOld settings for this instance.
arraySettings to save or bool false to cancel saving.update_callback(integer $deprecated = 1)
| since | 2.8.0 |
|---|---|
| global | array $wp_registered_widgets |
integerNot used.
$alt_option_name : string
| since | 2.8.0 |
|---|
$id : boolean | string
false| since | 2.8.0 |
|---|
$id_base : mixed | string
| since | 2.8.0 |
|---|
$name : string
| since | 2.8.0 |
|---|
$number : boolean | integer
false| since | 2.8.0 |
|---|
$option_name : string
| since | 2.8.0 |
|---|
$updated : boolean
falseSet to true when the data is updated after a POST submit - ensures it does not happen twice.
| since | 2.8.0 |
|---|