On this page
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().
Parameters
$argsarray Required-
Display arguments. See WP_Widget::widget() for information on accepted arguments.
More Arguments from WP_Widget::widget( ... $args )
Display arguments including'before_title','after_title','before_widget', and'after_widget'. $widget_argsint|array Optional-
Internal order number of the widget instance, or array of multi-widget arguments.
numberintNumber increment used for multiples of the same widget.
Default:
1
Source
File: wp-includes/class-wp-widget.php. View all references
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 );
}
}
}
Hooks
- apply_filters( 'widget_display_callback',
array $instance ,WP_Widget $widget ,array $args ) -
Filters the settings for a particular widget instance.
Related
Uses
| Uses | Description |
|---|---|
| wp_suspend_cache_addition() wp-includes/functions.php | Temporarily suspends cache additions. |
| WP_Widget::get_settings() wp-includes/class-wp-widget.php | Retrieves the settings for all instances of the widget class. |
| WP_Widget::_set() wp-includes/class-wp-widget.php | Sets the internal order number for the widget instance. |
| WP_Widget::is_preview() wp-includes/class-wp-widget.php | Determines whether the current request is inside the Customizer preview. |
| WP_Widget::widget() wp-includes/class-wp-widget.php | Echoes the widget content. |
| wp_parse_args() wp-includes/functions.php | Merges user defined arguments into defaults array. |
| apply_filters() wp-includes/plugin.php | Calls the callback functions that have been added to a filter hook. |
Changelog
| Version | Description |
|---|---|
| 2.8.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/classes/wp_widget/display_callback