WP_Widget::display_callback() WordPress Method

The WP_Widget::display_callback() method is used to display the content of a widget on a WordPress site. This method is called when a widget is being displayed on a page or post.

WP_Widget::display_callback( array $args, int|array $widget_args = 1 ) #

Generates the actual widget content (Do NOT override).


Description

Finds the instance and calls WP_Widget::widget().


Top ↑

Parameters

$args

(array)(Required)Display arguments. See WP_Widget::widget() for information on accepted arguments.

$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


Top ↑

Source

File: wp-includes/class-wp-widget.php

	public function display_callback( $args, $widget_args = 1 ) {
		if ( is_numeric( $widget_args ) ) {
			$widget_args = array( 'number' => $widget_args );
		}

		$widget_args = wp_parse_args( $widget_args, array( 'number' => -1 ) );
		$this->_set( $widget_args['number'] );
		$instances = $this->get_settings();

		if ( isset( $instances[ $this->number ] ) ) {
			$instance = $instances[ $this->number ];

			/**
			 * Filters the settings for a particular widget instance.
			 *
			 * Returning false will effectively short-circuit display of the widget.
			 *
			 * @since 2.8.0
			 *
			 * @param array     $instance The current widget instance's settings.
			 * @param WP_Widget $widget   The current widget instance.
			 * @param array     $args     An array of default widget arguments.
			 */
			$instance = apply_filters( 'widget_display_callback', $instance, $this, $args );

			if ( false === $instance ) {
				return;
			}

			$was_cache_addition_suspended = wp_suspend_cache_addition();
			if ( $this->is_preview() && ! $was_cache_addition_suspended ) {
				wp_suspend_cache_addition( true );
			}

			$this->widget( $args, $instance );

			if ( $this->is_preview() ) {
				wp_suspend_cache_addition( $was_cache_addition_suspended );
			}
		}
	}


Top ↑

Changelog

Changelog
VersionDescription
2.8.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.