From e4bb49ee5dd4edac69e996e2a6a162bfdb4205d9 Mon Sep 17 00:00:00 2001 From: azaozz Date: Wed, 13 May 2009 20:43:49 +0000 Subject: [PATCH] Add a function to output a generic widget anywhere in a template, props Denis-de-Bernardy, fixes #9701 git-svn-id: http://svn.automattic.com/wordpress/trunk@11317 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/widgets.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/wp-includes/widgets.php b/wp-includes/widgets.php index d2875a003..5f7f33c92 100644 --- a/wp-includes/widgets.php +++ b/wp-includes/widgets.php @@ -1190,3 +1190,31 @@ function register_widget_control($name, $control_callback, $width = '', $height function unregister_widget_control($id) { return wp_unregister_widget_control($id); } + +/** + * Output an arbitrary widget as a template tag + * + * @since 2.8 + * + * @param string $widget the widget's PHP class name (see default-widgets.php) + * @param array $instance the widget's instance settings + * @param array $args the widget's sidebar args + * @return void + **/ + +function the_widget($widget, $instance = array(), $args = array()) { + global $wp_widget_factory; + + $widget_obj = $wp_widget_factory->widgets[$widget]; + if ( !is_a($widget_obj, 'WP_Widget') ) + return; + + $before_widget = sprintf('
', $widget_obj->widget_options['classname']); + $default_args = array('before_widget' => $before_widget, 'after_widget' => "
", 'before_title' => '

', 'after_title' => '

'); + + $args = wp_parse_args($args, $default_args); + $instance = wp_parse_args($instance); + + $widget_obj->_set(-1); + $widget_obj->widget($args, $instance); +}