From 837bf2b6e6f775e6628bee71c5d43dc7ec4bc291 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Lavoie?= <seb@wemakecustom.com>
Date: Wed, 4 Apr 2012 17:27:21 -0400
Subject: [PATCH] applied and modified patch
 http://core.trac.wordpress.org/attachment/ticket/10976/10976.widget-content.diff

---
 wp-admin/widgets.php            |    2 +
 wp-includes/default-widgets.php |  118 ++++++++++++++++++++++++++------
 wp-includes/widgets.php         |   17 ++++-
 3 files changed, 113 insertions(+), 24 deletions(-)

diff --git a/wp-admin/widgets.php b/wp-admin/widgets.php
index 6c05e53..771a0dd 100644
--- a/wp-admin/widgets.php
+++ b/wp-admin/widgets.php
@@ -121,6 +121,8 @@ register_sidebar(array(
 	'after_widget' => '',
 	'before_title' => '',
 	'after_title' => '',
+	'before_content' => '',
+	'after_content' => '',
 ));
 
 retrieve_widgets();
diff --git a/wp-includes/default-widgets.php b/wp-includes/default-widgets.php
index df7ef39..456e1d9 100644
--- a/wp-includes/default-widgets.php
+++ b/wp-includes/default-widgets.php
@@ -34,11 +34,13 @@ class WP_Widget_Pages extends WP_Widget {
 			echo $before_widget;
 			if ( $title)
 				echo $before_title . $title . $after_title;
+			echo $before_content;
 		?>
 		<ul>
 			<?php echo $out; ?>
 		</ul>
 		<?php
+			echo $after_content;
 			echo $after_widget;
 		}
 	}
@@ -103,6 +105,19 @@ class WP_Widget_Links extends WP_Widget {
 		$show_images = isset($instance['images']) ? $instance['images'] : true;
 		$category = isset($instance['category']) ? $instance['category'] : false;
 
+		$link_args = array(
+			'title_before' => $before_title,
+			'title_after' => $after_title . $before_content,
+			'category_before' => $before_widget,
+			'category_after' => $after_widget,
+			'show_images' => $show_images,
+			'show_description' => $show_description,
+			'show_name' => $show_name,
+			'show_rating' => $show_rating,
+			'category' => $category,
+			'class' => 'linkcat widget'
+		);
+
 		if ( is_admin() && !$category ) {
 			// Display All Links widget as such in the widgets screen
 			echo $before_widget . $before_title . _x('All Links', 'links widget') . $after_title . $after_widget;
@@ -110,18 +125,19 @@ class WP_Widget_Links extends WP_Widget {
 		}
 
 		$before_widget = preg_replace('/id="[^"]*"/','id="%id"', $before_widget);
-		wp_list_bookmarks(apply_filters('widget_links_args', array(
-			'title_before' => $before_title, 'title_after' => $after_title,
-			'category_before' => $before_widget, 'category_after' => $after_widget,
-			'show_images' => $show_images, 'show_description' => $show_description,
-			'show_name' => $show_name, 'show_rating' => $show_rating,
-			'category' => $category, 'class' => 'linkcat widget'
-		)));
+
+		echo $before_widget;
+
+		wp_list_bookmarks( apply_filters( 'widget_links_args', $link_args ) );
+
+		echo $after_content;
+
+		echo $after_widget;
 	}
 
 	function update( $new_instance, $old_instance ) {
 		$new_instance = (array) $new_instance;
-		$instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0);
+		$instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0 );
 		foreach ( $instance as $field => $val ) {
 			if ( isset($new_instance[$field]) )
 				$instance[$field] = 1;
@@ -183,8 +199,9 @@ class WP_Widget_Search extends WP_Widget {
 		if ( $title )
 			echo $before_title . $title . $after_title;
 
-		// Use current theme search form if it exists
-		get_search_form();
+		echo $before_content;
+		get_search_form(); // Use current theme search form if it exists
+		echo $after_content;
 
 		echo $after_widget;
 	}
@@ -228,6 +245,7 @@ class WP_Widget_Archives extends WP_Widget {
 		if ( $title )
 			echo $before_title . $title . $after_title;
 
+		echo $before_content;
 		if ( $d ) {
 ?>
 		<select name="archive-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'> <option value=""><?php echo esc_attr(__('Select Month')); ?></option> <?php wp_get_archives(apply_filters('widget_archives_dropdown_args', array('type' => 'monthly', 'format' => 'option', 'show_post_count' => $c))); ?> </select>
@@ -239,6 +257,7 @@ class WP_Widget_Archives extends WP_Widget {
 		</ul>
 <?php
 		}
+		echo $after_content;
 
 		echo $after_widget;
 	}
@@ -290,6 +309,8 @@ class WP_Widget_Meta extends WP_Widget {
 		echo $before_widget;
 		if ( $title )
 			echo $before_title . $title . $after_title;
+			
+			echo $before_content;
 ?>
 			<ul>
 			<?php wp_register(); ?>
@@ -300,6 +321,8 @@ class WP_Widget_Meta extends WP_Widget {
 			<?php wp_meta(); ?>
 			</ul>
 <?php
+		echo $after_content;
+
 		echo $after_widget;
 	}
 
@@ -334,12 +357,24 @@ class WP_Widget_Calendar extends WP_Widget {
 	function widget( $args, $instance ) {
 		extract($args);
 		$title = apply_filters('widget_title', empty($instance['title']) ? '&nbsp;' : $instance['title'], $instance, $this->id_base);
+
 		echo $before_widget;
+
 		if ( $title )
 			echo $before_title . $title . $after_title;
-		echo '<div id="calendar_wrap">';
+
+		if ( '' != $before_content )
+			echo $before_content;
+		else
+			echo '<div id="calendar_wrap">';
+
 		get_calendar();
-		echo '</div>';
+
+		if ( '' != $after_content )
+			echo $after_content;
+		else
+			echo '</div>';
+
 		echo $after_widget;
 	}
 
@@ -378,9 +413,24 @@ class WP_Widget_Text extends WP_Widget {
 		$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base );
 		$text = apply_filters( 'widget_text', empty( $instance['text'] ) ? '' : $instance['text'], $instance );
 		echo $before_widget;
-		if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?>
-			<div class="textwidget"><?php echo !empty( $instance['filter'] ) ? wpautop( $text ) : $text; ?></div>
-		<?php
+
+		echo $before_widget;
+
+		if ( !empty( $title ) )
+			echo $before_title . $title . $after_title;
+
+		if ( '' != $before_content )
+			echo $before_content;
+		else
+			echo '<div class="textwidget">';
+
+		echo $instance['filter'] ? wpautop( $text ) : $text;
+
+		if ( '' != $after_content )
+			echo $after_content;
+		else
+			echo '</div>';
+
 		echo $after_widget;
 	}
 
@@ -431,10 +481,13 @@ class WP_Widget_Categories extends WP_Widget {
 		$d = ! empty( $instance['dropdown'] ) ? '1' : '0';
 
 		echo $before_widget;
+
 		if ( $title )
 			echo $before_title . $title . $after_title;
 
-		$cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h);
+		echo $before_content;
+
+		$cat_args = array( 'orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h );
 
 		if ( $d ) {
 			$cat_args['show_option_none'] = __('Select Category');
@@ -459,12 +512,14 @@ class WP_Widget_Categories extends WP_Widget {
 		<ul>
 <?php
 		$cat_args['title_li'] = '';
-		wp_list_categories(apply_filters('widget_categories_args', $cat_args));
+		wp_list_categories( apply_filters( 'widget_categories_args', $cat_args ) );
 ?>
 		</ul>
 <?php
 		}
 
+		echo $after_content;
+
 		echo $after_widget;
 	}
 
@@ -545,11 +600,13 @@ class WP_Widget_Recent_Posts extends WP_Widget {
 ?>
 		<?php echo $before_widget; ?>
 		<?php if ( $title ) echo $before_title . $title . $after_title; ?>
+		<?php echo $before_content; ?>
 		<ul>
 		<?php  while ($r->have_posts()) : $r->the_post(); ?>
-		<li><a href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?></a></li>
+			<li><a href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?></a></li>
 		<?php endwhile; ?>
 		</ul>
+		<?php echo $after_content; ?>
 		<?php echo $after_widget; ?>
 <?php
 		// Reset the global $the_post as this query will have stomped on it
@@ -651,6 +708,7 @@ class WP_Widget_Recent_Comments extends WP_Widget {
 		if ( $title )
 			$output .= $before_title . $title . $after_title;
 
+		$output .= $before_content;
 		$output .= '<ul id="recentcomments">';
 		if ( $comments ) {
 			foreach ( (array) $comments as $comment) {
@@ -658,6 +716,7 @@ class WP_Widget_Recent_Comments extends WP_Widget {
 			}
  		}
 		$output .= '</ul>';
+		$output .= $after_content;
 		$output .= $after_widget;
 
 		echo $output;
@@ -748,7 +807,9 @@ class WP_Widget_RSS extends WP_Widget {
 		echo $before_widget;
 		if ( $title )
 			echo $before_title . $title . $after_title;
+		echo $before_content;
 		wp_widget_rss_output( $rss, $instance );
+		echo $after_content;
 		echo $after_widget;
 
 		if ( ! is_wp_error($rss) )
@@ -1012,11 +1073,22 @@ class WP_Widget_Tag_Cloud extends WP_Widget {
 		$title = apply_filters('widget_title', $title, $instance, $this->id_base);
 
 		echo $before_widget;
+
 		if ( $title )
 			echo $before_title . $title . $after_title;
-		echo '<div class="tagcloud">';
+
+		if ( '' != $before_content )
+			echo $before_content;
+		else
+			echo '<div class="tagcloud">';
+
 		wp_tag_cloud( apply_filters('widget_tag_cloud_args', array('taxonomy' => $current_taxonomy) ) );
-		echo "</div>\n";
+
+		if ( '' != $after_content )
+			echo $after_content;
+		else
+			echo "</div>\n";
+
 		echo $after_widget;
 	}
 
@@ -1056,7 +1128,7 @@ class WP_Widget_Tag_Cloud extends WP_Widget {
  *
  * @since 3.0.0
  */
- class WP_Nav_Menu_Widget extends WP_Widget {
+class WP_Nav_Menu_Widget extends WP_Widget {
 
 	function __construct() {
 		$widget_ops = array( 'description' => __('Use this widget to add one of your custom menus as a widget.') );
@@ -1077,8 +1149,12 @@ class WP_Widget_Tag_Cloud extends WP_Widget {
 		if ( !empty($instance['title']) )
 			echo $args['before_title'] . $instance['title'] . $args['after_title'];
 
+		echo $args['before_content'];
+
 		wp_nav_menu( array( 'fallback_cb' => '', 'menu' => $nav_menu ) );
 
+		echo $args['after_content'];
+
 		echo $args['after_widget'];
 	}
 
diff --git a/wp-includes/widgets.php b/wp-includes/widgets.php
index 2dfafcb..5d51d2c 100644
--- a/wp-includes/widgets.php
+++ b/wp-includes/widgets.php
@@ -38,7 +38,7 @@ class WP_Widget {
 	 *
 	 * Subclasses should over-ride this function to generate their widget code.
 	 *
-	 * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget.
+	 * @param array $args Display arguments including before_title, after_title, before_widget, after_widget, before_content, and after_content.
 	 * @param array $instance The settings for the particular instance of the widget
 	 */
 	function widget($args, $instance) {
@@ -528,6 +528,8 @@ function register_sidebars($number = 1, $args = array()) {
  *     displayed.
  * before_title - The content that will be prepended to the title when displayed.
  * after_title - the content that will be appended to the title when displayed.
+ * before_content - The content that will be prepended to the widget content when displayed.
+ * after_content - the content that will be appended to the widget content when displayed.
  *
  * <em>Content</em> is assumed to be HTML and should be formatted as such, but
  * doesn't have to be.
@@ -552,6 +554,8 @@ function register_sidebar($args = array()) {
 		'after_widget' => "</li>\n",
 		'before_title' => '<h2 class="widgettitle">',
 		'after_title' => "</h2>\n",
+		'before_content' => '',
+		'after_content' => '',
 	);
 
 	$sidebar = wp_parse_args( $args, $defaults );
@@ -1126,8 +1130,15 @@ function the_widget($widget, $instance = array(), $args = array()) {
 	if ( !is_a($widget_obj, 'WP_Widget') )
 		return;
 
-	$before_widget = sprintf('<div class="widget %s">', $widget_obj->widget_options['classname'] );
-	$default_args = array( 'before_widget' => $before_widget, 'after_widget' => "</div>", 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>' );
+	$before_widget = sprintf( '<div class="widget %s">', $widget_obj->widget_options['classname'] );
+	$default_args = array(
+		'before_widget' => $before_widget,
+		'after_widget' => "</div>",
+		'before_title' => '<h2 class="widgettitle">',
+		'after_title' => '</h2>',
+		'before_content' => '',
+		'after_content' => ''
+	);
 
 	$args = wp_parse_args($args, $default_args);
 	$instance = wp_parse_args($instance);
-- 
1.7.9.4

