WP_Widget::form_callback() WordPress Method
The WP_Widget::form_callback() method is used to display the widget form in the admin interface. This method is called when the user adds a new widget to their sidebar.
WP_Widget::form_callback( int|array $widget_args = 1 ) #
Generates the widget control form (Do NOT override).
Parameters
- $widget_args
(int|array)(Optional)Internal order number of the widget instance, or array of multi-widget arguments.
- 'number'
(int) Number increment used for multiples of the same widget.
Default value: 1
- 'number'
Return
(string|null)
Source
File: wp-includes/class-wp-widget.php
public function form_callback( $widget_args = 1 ) { if ( is_numeric( $widget_args ) ) { $widget_args = array( 'number' => $widget_args ); } $widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) ); $all_instances = $this->get_settings(); if ( -1 == $widget_args['number'] ) { // We echo out a form where 'number' can be set later. $this->_set( '__i__' ); $instance = array(); } else { $this->_set( $widget_args['number'] ); $instance = $all_instances[ $widget_args['number'] ]; } /** * Filters the widget instance's settings before displaying the control form. * * Returning false effectively short-circuits display of the control form. * * @since 2.8.0 * * @param array $instance The current widget instance's settings. * @param WP_Widget $widget The current widget instance. */ $instance = apply_filters( 'widget_form_callback', $instance, $this ); $return = null; if ( false !== $instance ) { $return = $this->form( $instance ); /** * Fires at the end of the widget control form. * * Use this hook to add extra fields to the widget form. The hook * is only fired if the value passed to the 'widget_form_callback' * hook is not false. * * Note: If the widget has no form, the text echoed from the default * form method can be hidden using CSS. * * @since 2.8.0 * * @param WP_Widget $widget The widget instance (passed by reference). * @param null $return Return null if new fields are added. * @param array $instance An array of the widget's settings. */ do_action_ref_array( 'in_widget_form', array( &$this, &$return, $instance ) ); } return $return; }
Expand full source codeCollapse full source codeView on TracView on GitHub
Changelog
Version | Description |
---|---|
2.8.0 | Introduced. |