WP_Widget::form_callback()publicWP 2.8.0

Generates the widget control form (Do NOT override).

Метод класса: WP_Widget{}

Хуки из метода

Возвращает

Строку|null.

Использование

$WP_Widget = new WP_Widget();
$WP_Widget->form_callback( $widget_args );
$widget_args(int|массив)

Internal order number of the widget instance, or array of multi-widget arguments.

По умолчанию: 1

  • number(int)
    Number increment used for multiples of the same widget.

Список изменений

С версии 2.8.0 Введена.

Код WP_Widget::form_callback() WP 6.6.2

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;
}