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 |
string
Optional 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.
string
Name for the widget displayed on the configuration page.
array
Optional. Widget options. See wp_register_sidebar_widget() for information on accepted arguments. Default empty array.
array
Optional. 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 |
---|
string
Optional 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.
string
Name for the widget displayed on the configuration page.
array
Optional. Widget options. See wp_register_sidebar_widget() for information on accepted arguments. Default empty array.
array
Optional. Widget control options. See wp_register_widget_control() for information on accepted arguments. Default empty array.
_get_display_callback() : callable
since | 2.8.0 |
---|
callable
Display callback._get_form_callback() : callable
since | 2.8.0 |
---|
callable
Form callback._get_update_callback() : callable
since | 2.8.0 |
---|
callable
Update callback._register()
since | 2.8.0 |
---|
_register_one(integer $number = -1
)
since | 2.8.0 |
---|
integer
Optional. 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 |
---|
integer
The 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 |
---|
array
Display arguments. See WP_Widget::widget() for information on accepted arguments.
integer
array
{ 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 |
---|
array
Current settings.
string
Default return is 'noform'.form_callback(integer|array $widget_args = 1
) : string | null
since | 2.8.0 |
---|
integer
array
{ 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.
}
string
null
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. |
string
Field name.
string
ID 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. |
string
Field name
string
Name attribute for $field_nameget_settings() : array
since | 2.8.0 |
---|
array
Multi-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 |
boolean
True if within the Customizer preview, false if not.save_settings(array $settings)
since | 2.8.0 |
---|
array
Multi-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 |
---|
array
New settings for this instance as input by the user via WP_Widget::form().
array
Old settings for this instance.
array
Settings to save or bool false to cancel saving.update_callback(integer $deprecated = 1
)
since | 2.8.0 |
---|---|
global | array $wp_registered_widgets |
integer
Not 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
false
Set to true when the data is updated after a POST submit - ensures it does not happen twice.
since | 2.8.0 |
---|