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
|
b
|
register_sidebar(array( |
121 | 121 | 'after_widget' => '', |
122 | 122 | 'before_title' => '', |
123 | 123 | 'after_title' => '', |
| 124 | 'before_content' => '', |
| 125 | 'after_content' => '', |
124 | 126 | )); |
125 | 127 | |
126 | 128 | retrieve_widgets(); |
diff --git a/wp-includes/default-widgets.php b/wp-includes/default-widgets.php
index df7ef39..456e1d9 100644
a
|
b
|
class WP_Widget_Pages extends WP_Widget { |
34 | 34 | echo $before_widget; |
35 | 35 | if ( $title) |
36 | 36 | echo $before_title . $title . $after_title; |
| 37 | echo $before_content; |
37 | 38 | ?> |
38 | 39 | <ul> |
39 | 40 | <?php echo $out; ?> |
40 | 41 | </ul> |
41 | 42 | <?php |
| 43 | echo $after_content; |
42 | 44 | echo $after_widget; |
43 | 45 | } |
44 | 46 | } |
… |
… |
class WP_Widget_Links extends WP_Widget { |
103 | 105 | $show_images = isset($instance['images']) ? $instance['images'] : true; |
104 | 106 | $category = isset($instance['category']) ? $instance['category'] : false; |
105 | 107 | |
| 108 | $link_args = array( |
| 109 | 'title_before' => $before_title, |
| 110 | 'title_after' => $after_title . $before_content, |
| 111 | 'category_before' => $before_widget, |
| 112 | 'category_after' => $after_widget, |
| 113 | 'show_images' => $show_images, |
| 114 | 'show_description' => $show_description, |
| 115 | 'show_name' => $show_name, |
| 116 | 'show_rating' => $show_rating, |
| 117 | 'category' => $category, |
| 118 | 'class' => 'linkcat widget' |
| 119 | ); |
| 120 | |
106 | 121 | if ( is_admin() && !$category ) { |
107 | 122 | // Display All Links widget as such in the widgets screen |
108 | 123 | echo $before_widget . $before_title . _x('All Links', 'links widget') . $after_title . $after_widget; |
… |
… |
class WP_Widget_Links extends WP_Widget { |
110 | 125 | } |
111 | 126 | |
112 | 127 | $before_widget = preg_replace('/id="[^"]*"/','id="%id"', $before_widget); |
113 | | wp_list_bookmarks(apply_filters('widget_links_args', array( |
114 | | 'title_before' => $before_title, 'title_after' => $after_title, |
115 | | 'category_before' => $before_widget, 'category_after' => $after_widget, |
116 | | 'show_images' => $show_images, 'show_description' => $show_description, |
117 | | 'show_name' => $show_name, 'show_rating' => $show_rating, |
118 | | 'category' => $category, 'class' => 'linkcat widget' |
119 | | ))); |
| 128 | |
| 129 | echo $before_widget; |
| 130 | |
| 131 | wp_list_bookmarks( apply_filters( 'widget_links_args', $link_args ) ); |
| 132 | |
| 133 | echo $after_content; |
| 134 | |
| 135 | echo $after_widget; |
120 | 136 | } |
121 | 137 | |
122 | 138 | function update( $new_instance, $old_instance ) { |
123 | 139 | $new_instance = (array) $new_instance; |
124 | | $instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0); |
| 140 | $instance = array( 'images' => 0, 'name' => 0, 'description' => 0, 'rating' => 0 ); |
125 | 141 | foreach ( $instance as $field => $val ) { |
126 | 142 | if ( isset($new_instance[$field]) ) |
127 | 143 | $instance[$field] = 1; |
… |
… |
class WP_Widget_Search extends WP_Widget { |
183 | 199 | if ( $title ) |
184 | 200 | echo $before_title . $title . $after_title; |
185 | 201 | |
186 | | // Use current theme search form if it exists |
187 | | get_search_form(); |
| 202 | echo $before_content; |
| 203 | get_search_form(); // Use current theme search form if it exists |
| 204 | echo $after_content; |
188 | 205 | |
189 | 206 | echo $after_widget; |
190 | 207 | } |
… |
… |
class WP_Widget_Archives extends WP_Widget { |
228 | 245 | if ( $title ) |
229 | 246 | echo $before_title . $title . $after_title; |
230 | 247 | |
| 248 | echo $before_content; |
231 | 249 | if ( $d ) { |
232 | 250 | ?> |
233 | 251 | <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> |
… |
… |
class WP_Widget_Archives extends WP_Widget { |
239 | 257 | </ul> |
240 | 258 | <?php |
241 | 259 | } |
| 260 | echo $after_content; |
242 | 261 | |
243 | 262 | echo $after_widget; |
244 | 263 | } |
… |
… |
class WP_Widget_Meta extends WP_Widget { |
290 | 309 | echo $before_widget; |
291 | 310 | if ( $title ) |
292 | 311 | echo $before_title . $title . $after_title; |
| 312 | |
| 313 | echo $before_content; |
293 | 314 | ?> |
294 | 315 | <ul> |
295 | 316 | <?php wp_register(); ?> |
… |
… |
class WP_Widget_Meta extends WP_Widget { |
300 | 321 | <?php wp_meta(); ?> |
301 | 322 | </ul> |
302 | 323 | <?php |
| 324 | echo $after_content; |
| 325 | |
303 | 326 | echo $after_widget; |
304 | 327 | } |
305 | 328 | |
… |
… |
class WP_Widget_Calendar extends WP_Widget { |
334 | 357 | function widget( $args, $instance ) { |
335 | 358 | extract($args); |
336 | 359 | $title = apply_filters('widget_title', empty($instance['title']) ? ' ' : $instance['title'], $instance, $this->id_base); |
| 360 | |
337 | 361 | echo $before_widget; |
| 362 | |
338 | 363 | if ( $title ) |
339 | 364 | echo $before_title . $title . $after_title; |
340 | | echo '<div id="calendar_wrap">'; |
| 365 | |
| 366 | if ( '' != $before_content ) |
| 367 | echo $before_content; |
| 368 | else |
| 369 | echo '<div id="calendar_wrap">'; |
| 370 | |
341 | 371 | get_calendar(); |
342 | | echo '</div>'; |
| 372 | |
| 373 | if ( '' != $after_content ) |
| 374 | echo $after_content; |
| 375 | else |
| 376 | echo '</div>'; |
| 377 | |
343 | 378 | echo $after_widget; |
344 | 379 | } |
345 | 380 | |
… |
… |
class WP_Widget_Text extends WP_Widget { |
378 | 413 | $title = apply_filters( 'widget_title', empty( $instance['title'] ) ? '' : $instance['title'], $instance, $this->id_base ); |
379 | 414 | $text = apply_filters( 'widget_text', empty( $instance['text'] ) ? '' : $instance['text'], $instance ); |
380 | 415 | echo $before_widget; |
381 | | if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?> |
382 | | <div class="textwidget"><?php echo !empty( $instance['filter'] ) ? wpautop( $text ) : $text; ?></div> |
383 | | <?php |
| 416 | |
| 417 | echo $before_widget; |
| 418 | |
| 419 | if ( !empty( $title ) ) |
| 420 | echo $before_title . $title . $after_title; |
| 421 | |
| 422 | if ( '' != $before_content ) |
| 423 | echo $before_content; |
| 424 | else |
| 425 | echo '<div class="textwidget">'; |
| 426 | |
| 427 | echo $instance['filter'] ? wpautop( $text ) : $text; |
| 428 | |
| 429 | if ( '' != $after_content ) |
| 430 | echo $after_content; |
| 431 | else |
| 432 | echo '</div>'; |
| 433 | |
384 | 434 | echo $after_widget; |
385 | 435 | } |
386 | 436 | |
… |
… |
class WP_Widget_Categories extends WP_Widget { |
431 | 481 | $d = ! empty( $instance['dropdown'] ) ? '1' : '0'; |
432 | 482 | |
433 | 483 | echo $before_widget; |
| 484 | |
434 | 485 | if ( $title ) |
435 | 486 | echo $before_title . $title . $after_title; |
436 | 487 | |
437 | | $cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h); |
| 488 | echo $before_content; |
| 489 | |
| 490 | $cat_args = array( 'orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h ); |
438 | 491 | |
439 | 492 | if ( $d ) { |
440 | 493 | $cat_args['show_option_none'] = __('Select Category'); |
… |
… |
class WP_Widget_Categories extends WP_Widget { |
459 | 512 | <ul> |
460 | 513 | <?php |
461 | 514 | $cat_args['title_li'] = ''; |
462 | | wp_list_categories(apply_filters('widget_categories_args', $cat_args)); |
| 515 | wp_list_categories( apply_filters( 'widget_categories_args', $cat_args ) ); |
463 | 516 | ?> |
464 | 517 | </ul> |
465 | 518 | <?php |
466 | 519 | } |
467 | 520 | |
| 521 | echo $after_content; |
| 522 | |
468 | 523 | echo $after_widget; |
469 | 524 | } |
470 | 525 | |
… |
… |
class WP_Widget_Recent_Posts extends WP_Widget { |
545 | 600 | ?> |
546 | 601 | <?php echo $before_widget; ?> |
547 | 602 | <?php if ( $title ) echo $before_title . $title . $after_title; ?> |
| 603 | <?php echo $before_content; ?> |
548 | 604 | <ul> |
549 | 605 | <?php while ($r->have_posts()) : $r->the_post(); ?> |
550 | | <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> |
| 606 | <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> |
551 | 607 | <?php endwhile; ?> |
552 | 608 | </ul> |
| 609 | <?php echo $after_content; ?> |
553 | 610 | <?php echo $after_widget; ?> |
554 | 611 | <?php |
555 | 612 | // Reset the global $the_post as this query will have stomped on it |
… |
… |
class WP_Widget_Recent_Comments extends WP_Widget { |
651 | 708 | if ( $title ) |
652 | 709 | $output .= $before_title . $title . $after_title; |
653 | 710 | |
| 711 | $output .= $before_content; |
654 | 712 | $output .= '<ul id="recentcomments">'; |
655 | 713 | if ( $comments ) { |
656 | 714 | foreach ( (array) $comments as $comment) { |
… |
… |
class WP_Widget_Recent_Comments extends WP_Widget { |
658 | 716 | } |
659 | 717 | } |
660 | 718 | $output .= '</ul>'; |
| 719 | $output .= $after_content; |
661 | 720 | $output .= $after_widget; |
662 | 721 | |
663 | 722 | echo $output; |
… |
… |
class WP_Widget_RSS extends WP_Widget { |
748 | 807 | echo $before_widget; |
749 | 808 | if ( $title ) |
750 | 809 | echo $before_title . $title . $after_title; |
| 810 | echo $before_content; |
751 | 811 | wp_widget_rss_output( $rss, $instance ); |
| 812 | echo $after_content; |
752 | 813 | echo $after_widget; |
753 | 814 | |
754 | 815 | if ( ! is_wp_error($rss) ) |
… |
… |
class WP_Widget_Tag_Cloud extends WP_Widget { |
1012 | 1073 | $title = apply_filters('widget_title', $title, $instance, $this->id_base); |
1013 | 1074 | |
1014 | 1075 | echo $before_widget; |
| 1076 | |
1015 | 1077 | if ( $title ) |
1016 | 1078 | echo $before_title . $title . $after_title; |
1017 | | echo '<div class="tagcloud">'; |
| 1079 | |
| 1080 | if ( '' != $before_content ) |
| 1081 | echo $before_content; |
| 1082 | else |
| 1083 | echo '<div class="tagcloud">'; |
| 1084 | |
1018 | 1085 | wp_tag_cloud( apply_filters('widget_tag_cloud_args', array('taxonomy' => $current_taxonomy) ) ); |
1019 | | echo "</div>\n"; |
| 1086 | |
| 1087 | if ( '' != $after_content ) |
| 1088 | echo $after_content; |
| 1089 | else |
| 1090 | echo "</div>\n"; |
| 1091 | |
1020 | 1092 | echo $after_widget; |
1021 | 1093 | } |
1022 | 1094 | |
… |
… |
class WP_Widget_Tag_Cloud extends WP_Widget { |
1056 | 1128 | * |
1057 | 1129 | * @since 3.0.0 |
1058 | 1130 | */ |
1059 | | class WP_Nav_Menu_Widget extends WP_Widget { |
| 1131 | class WP_Nav_Menu_Widget extends WP_Widget { |
1060 | 1132 | |
1061 | 1133 | function __construct() { |
1062 | 1134 | $widget_ops = array( 'description' => __('Use this widget to add one of your custom menus as a widget.') ); |
… |
… |
class WP_Widget_Tag_Cloud extends WP_Widget { |
1077 | 1149 | if ( !empty($instance['title']) ) |
1078 | 1150 | echo $args['before_title'] . $instance['title'] . $args['after_title']; |
1079 | 1151 | |
| 1152 | echo $args['before_content']; |
| 1153 | |
1080 | 1154 | wp_nav_menu( array( 'fallback_cb' => '', 'menu' => $nav_menu ) ); |
1081 | 1155 | |
| 1156 | echo $args['after_content']; |
| 1157 | |
1082 | 1158 | echo $args['after_widget']; |
1083 | 1159 | } |
1084 | 1160 | |
diff --git a/wp-includes/widgets.php b/wp-includes/widgets.php
index 2dfafcb..5d51d2c 100644
a
|
b
|
class WP_Widget { |
38 | 38 | * |
39 | 39 | * Subclasses should over-ride this function to generate their widget code. |
40 | 40 | * |
41 | | * @param array $args Display arguments including before_title, after_title, before_widget, and after_widget. |
| 41 | * @param array $args Display arguments including before_title, after_title, before_widget, after_widget, before_content, and after_content. |
42 | 42 | * @param array $instance The settings for the particular instance of the widget |
43 | 43 | */ |
44 | 44 | function widget($args, $instance) { |
… |
… |
function register_sidebars($number = 1, $args = array()) { |
528 | 528 | * displayed. |
529 | 529 | * before_title - The content that will be prepended to the title when displayed. |
530 | 530 | * after_title - the content that will be appended to the title when displayed. |
| 531 | * before_content - The content that will be prepended to the widget content when displayed. |
| 532 | * after_content - the content that will be appended to the widget content when displayed. |
531 | 533 | * |
532 | 534 | * <em>Content</em> is assumed to be HTML and should be formatted as such, but |
533 | 535 | * doesn't have to be. |
… |
… |
function register_sidebar($args = array()) { |
552 | 554 | 'after_widget' => "</li>\n", |
553 | 555 | 'before_title' => '<h2 class="widgettitle">', |
554 | 556 | 'after_title' => "</h2>\n", |
| 557 | 'before_content' => '', |
| 558 | 'after_content' => '', |
555 | 559 | ); |
556 | 560 | |
557 | 561 | $sidebar = wp_parse_args( $args, $defaults ); |
… |
… |
function the_widget($widget, $instance = array(), $args = array()) { |
1126 | 1130 | if ( !is_a($widget_obj, 'WP_Widget') ) |
1127 | 1131 | return; |
1128 | 1132 | |
1129 | | $before_widget = sprintf('<div class="widget %s">', $widget_obj->widget_options['classname'] ); |
1130 | | $default_args = array( 'before_widget' => $before_widget, 'after_widget' => "</div>", 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>' ); |
| 1133 | $before_widget = sprintf( '<div class="widget %s">', $widget_obj->widget_options['classname'] ); |
| 1134 | $default_args = array( |
| 1135 | 'before_widget' => $before_widget, |
| 1136 | 'after_widget' => "</div>", |
| 1137 | 'before_title' => '<h2 class="widgettitle">', |
| 1138 | 'after_title' => '</h2>', |
| 1139 | 'before_content' => '', |
| 1140 | 'after_content' => '' |
| 1141 | ); |
1131 | 1142 | |
1132 | 1143 | $args = wp_parse_args($args, $default_args); |
1133 | 1144 | $instance = wp_parse_args($instance); |