Make WordPress Core

Ticket #11387: walker_widget.patch

File walker_widget.patch, 34.8 KB (added by ShaneF, 15 years ago)
  • wp-includes/bookmark-template.php

     
    251251        echo $output;
    252252}
    253253
     254/**
     255 *
     256 * @param $args
     257 * @return unknown_type
     258 */
     259function wp_list_bookmarks_widget($args = '') {
     260        $defaults = array(
     261                'orderby' => 'name', 'order' => 'ASC',
     262                'limit' => -1, 'category' => '', 'exclude_category' => '',
     263                'category_name' => '', 'hide_invisible' => 1,
     264                'show_updated' => 0, 'echo' => 1,
     265                'categorize' => 1, 'title_li' => __('Bookmarks'),
     266                'title_before' => '<h2>', 'title_after' => '</h2>',
     267                'category_orderby' => 'name', 'category_order' => 'ASC',
     268                'class' => 'linkcat', 'category_before' => '<li id="%id" class="%class">',
     269                'category_after' => '</li>'
     270        );
     271
     272        $r = wp_parse_args( $args, $defaults );
     273        extract( $r, EXTR_SKIP );
     274
     275        $output = '';
     276
     277        if ( $categorize ) {
     278                $cats = get_terms('link_category', array('name__like' => $category_name, 'include' => $category, 'exclude' => $exclude_category, 'orderby' => $category_orderby, 'order' => $category_order, 'hierarchical' => 0));
     279
     280                foreach ( (array) $cats as $cat ) {
     281                        $params = array_merge($r, array('category' => $cat->term_id));
     282                        $bookmarks = get_bookmarks($params);
     283                        if ( empty($bookmarks) )
     284                                continue;
     285                       
     286                        $bookmarks_output[] = array(
     287                                'title' => apply_filters( "link_category", $cat->name ),
     288                                'output' => _walk_bookmarks($bookmarks, $r)
     289                        );
     290                       
     291                }
     292               
     293        } else {
     294                $bookmarks = get_bookmarks($r);
     295                if ( !empty($bookmarks) ) {
     296                        $bookmarks_output[] = array(
     297                                'title' => apply_filters( "link_category", $cat->name ),
     298                                'output' => _walk_bookmarks($bookmarks, $r)
     299                        );
     300                }
     301        }
     302       
     303        return $bookmarks_output;
     304}
     305
    254306?>
  • wp-includes/default-widgets.php

     
    2424
    2525                $title = apply_filters('widget_title', empty( $instance['title'] ) ? __( 'Pages' ) : $instance['title']);
    2626                $sortby = empty( $instance['sortby'] ) ? 'menu_order' : $instance['sortby'];
     27                $walker = empty( $instance['walker'] ) ? '' : $instance['walker'];
    2728                $exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude'];
    2829
    2930                if ( $sortby == 'menu_order' )
    3031                        $sortby = 'menu_order, post_title';
    31 
    32                 $out = wp_list_pages( apply_filters('widget_pages_args', array('title_li' => '', 'echo' => 0, 'sort_column' => $sortby, 'exclude' => $exclude) ) );
    33 
    34                 if ( !empty( $out ) ) {
    35                         echo $before_widget;
    36                         if ( $title)
    37                                 echo $before_title . $title . $after_title;
    38                 ?>
    39                 <ul>
    40                         <?php echo $out; ?>
    41                 </ul>
    42                 <?php
    43                         echo $after_widget;
    44                 }
     32               
     33                if (  !empty( $walker ) )
     34                        $page_walker = new $walker;
     35                       
     36                $pages_array = array('title_li' => '', 'echo' => 0, 'sort_column' => $sortby, 'exclude' => $exclude, 'walker' => $page_walker);
     37                $output = wp_list_pages( apply_filters('widget_pages_args', $pages_array ) );
     38               
     39                $widget_design = apply_filters( 'widget_design', new Widget_Basic);
     40                $widget_array = array(
     41                        'title'                 => apply_filters( 'widget_title' , $title ),
     42                        'before_output' => "<ul>",
     43                        'output'                => $output,
     44                        'after_output'  => "</ul>",
     45                        'style'                 => "li"
     46                );
     47                $widget_args = array(array_merge($args, $widget_array));
     48               
     49                echo call_user_func_array( array(&$widget_design, 'display'), $widget_args );   
     50               
    4551        }
    4652
    4753        function update( $new_instance, $old_instance ) {
     
    5258                } else {
    5359                        $instance['sortby'] = 'menu_order';
    5460                }
    55 
     61               
     62                $instance['walker'] = strip_tags( $new_instance['walker'] );
    5663                $instance['exclude'] = strip_tags( $new_instance['exclude'] );
    5764
    5865                return $instance;
     
    6067
    6168        function form( $instance ) {
    6269                //Defaults
    63                 $instance = wp_parse_args( (array) $instance, array( 'sortby' => 'post_title', 'title' => '', 'exclude' => '') );
     70                $instance = wp_parse_args( (array) $instance, array( 'sortby' => 'post_title', 'title' => '', 'walker' => '', 'exclude' => '') );
    6471                $title = esc_attr( $instance['title'] );
     72                $walker = esc_attr( $instance['walker'] );
    6573                $exclude = esc_attr( $instance['exclude'] );
    6674        ?>
    6775                <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p>
     
    7482                        </select>
    7583                </p>
    7684                <p>
     85                        <label for="<?php echo $this->get_field_id('walker'); ?>"><?php _e( 'Walker:' ); ?></label> <input type="text" value="<?php echo $walker; ?>" name="<?php echo $this->get_field_name('walker'); ?>" id="<?php echo $this->get_field_id('walker'); ?>" class="widefat" />
     86                        <br />
     87                        <small><?php _e( 'Customer Walker' ); ?></small>
    7788                        <label for="<?php echo $this->get_field_id('exclude'); ?>"><?php _e( 'Exclude:' ); ?></label> <input type="text" value="<?php echo $exclude; ?>" name="<?php echo $this->get_field_name('exclude'); ?>" id="<?php echo $this->get_field_id('exclude'); ?>" class="widefat" />
    7889                        <br />
    7990                        <small><?php _e( 'Page IDs, separated by commas.' ); ?></small>
     
    109120                        echo $before_widget . $before_title. __('All Links') . $after_title . $after_widget;
    110121                        return;
    111122                }
    112 
    113                 $before_widget = preg_replace('/id="[^"]*"/','id="%id"', $before_widget);
    114                 wp_list_bookmarks(apply_filters('widget_links_args', array(
    115                         'title_before' => $before_title, 'title_after' => $after_title,
    116                         'category_before' => $before_widget, 'category_after' => $after_widget,
     123               
     124                $links_data = wp_list_bookmarks_widget(apply_filters('widget_links_args', array(
     125                        'title_before' => '', 'title_after' => '', 'category_before' => '', 'category_after' => '',
    117126                        'show_images' => $show_images, 'show_description' => $show_description,
    118127                        'show_name' => $show_name, 'show_rating' => $show_rating,
    119128                        'category' => $category, 'class' => 'linkcat widget'
    120129                )));
     130                $widget_design = apply_filters( 'widget_design', new Widget_Basic);
     131                $widget_default_array = array('style' => 'li', 'before_output' => '<ul class="xoxo blogroll">', 'after_output' => '</ul>');
     132               
     133                foreach ($links_data as $links) {
     134                        $widget_array[] = array_merge($links, $widget_default_array);
     135                }
     136               
     137                foreach ($widget_array as $widget_display) {
     138                        echo call_user_func_array( array(&$widget_design, 'display'), array(array_merge($args, $widget_display)) );
     139                }
     140               
    121141        }
    122142
    123143        function update( $new_instance, $old_instance ) {
     
    180200                extract($args);
    181201                $title = apply_filters('widget_title', $instance['title']);
    182202
    183                 echo $before_widget;
    184                 if ( $title )
    185                         echo $before_title . $title . $after_title;
     203                $widget_design = apply_filters( 'widget_design', new Widget_Search);
     204                $widget_array = array(
     205                        'title'                 => $title,
     206                        'output'                => get_search_form(false),
     207                        'style'                 => "none"
     208                );
     209                $widget_args = array(array_merge($args, $widget_array));
     210               
     211                echo call_user_func_array( array(&$widget_design, 'display'), $widget_args );
    186212
    187                 // Use current theme search form if it exists
    188                 get_search_form();
    189 
    190                 echo $after_widget;
    191213        }
    192214
    193215        function form( $instance ) {
     
    224246                $c = $instance['count'] ? '1' : '0';
    225247                $d = $instance['dropdown'] ? '1' : '0';
    226248                $title = apply_filters('widget_title', empty($instance['title']) ? __('Archives') : $instance['title']);
    227 
    228                 echo $before_widget;
    229                 if ( $title )
    230                         echo $before_title . $title . $after_title;
    231 
     249               
    232250                if ( $d ) {
    233 ?>
    234                 <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>
    235 <?php
     251                        $output = "<select name=\"archive-dropdown\" onchange='document.location.href=this.options[this.selectedIndex].value;'> <option value=\"\">". esc_attr(__('Select Month')) . "</option>" . wp_get_archives(apply_filters('widget_archives_dropdown_args', array('echo' => 0, 'type' => 'monthly', 'format' => 'option', 'show_post_count' => $c))) . "</select>";
    236252                } else {
    237 ?>
    238                 <ul>
    239                 <?php wp_get_archives(apply_filters('widget_archives_args', array('type' => 'monthly', 'show_post_count' => $c))); ?>
    240                 </ul>
    241 <?php
     253                        $output = wp_get_archives(apply_filters('widget_archives_args', array('echo' => 0, 'type' => 'monthly', 'show_post_count' => $c)));
    242254                }
    243 
    244                 echo $after_widget;
     255               
     256                $widget_design = apply_filters( 'widget_design', new Widget_Basic);
     257                $widget_array = array(
     258                        'title'                 => $title,
     259                        'before_output' => "<ul>",
     260                        'output'                => $output,
     261                        'after_output'  => "</ul>",
     262                        'style'                 => "li"
     263                );
     264                $widget_args = array(array_merge($args, $widget_array));
     265               
     266                echo call_user_func_array( array(&$widget_design, 'display'), $widget_args );
     267               
    245268        }
    246269
    247270        function update( $new_instance, $old_instance ) {
     
    287310        function widget( $args, $instance ) {
    288311                extract($args);
    289312                $title = apply_filters('widget_title', empty($instance['title']) ? __('Meta') : $instance['title']);
    290 
    291                 echo $before_widget;
    292                 if ( $title )
    293                         echo $before_title . $title . $after_title;
    294 ?>
    295                         <ul>
    296                         <?php wp_register(); ?>
    297                         <li><?php wp_loginout(); ?></li>
    298                         <li><a href="<?php bloginfo('rss2_url'); ?>" title="<?php echo esc_attr(__('Syndicate this site using RSS 2.0')); ?>"><?php _e('Entries <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
    299                         <li><a href="<?php bloginfo('comments_rss2_url'); ?>" title="<?php echo esc_attr(__('The latest comments to all posts in RSS')); ?>"><?php _e('Comments <abbr title="Really Simple Syndication">RSS</abbr>'); ?></a></li>
    300                         <li><a href="http://wordpress.org/" title="<?php echo esc_attr(__('Powered by WordPress, state-of-the-art semantic personal publishing platform.')); ?>">WordPress.org</a></li>
    301                         <?php wp_meta(); ?>
    302                         </ul>
    303 <?php
    304                 echo $after_widget;
     313               
     314                $widget_design = apply_filters( 'widget_design', new Widget_Basic);
     315                $widget_array = array(
     316                        'title'                 => $title,
     317                        'before_output' => "<ul>",
     318                        'output'                => "<li>" . wp_register('', '', false) . "</li><li>" . wp_loginout('', false) . "</li><li><a href='". get_bloginfo('rss2_url') . "' title='". __('Syndicate this site using RSS 2.0') . "'>" . __('Entries <abbr title="Really Simple Syndication">RSS</abbr>') . "</a></li><li><a href='" . get_bloginfo('comments_rss2_url') . "' title='" . __('The latest comments to all posts in RSS') . "'>" . __('Comments <abbr title="Really Simple Syndication">RSS</abbr>') . "</a></li><li><a href='http://wordpress.org/' title='" . __('Powered by WordPress, state-of-the-art semantic personal publishing platform.') . "'>WordPress.org</a></li>" . wp_meta(),
     319                        'after_output'  => "</ul>",
     320                );
     321                $widget_args = array(array_merge($args, $widget_array));
     322               
     323                echo call_user_func_array( array(&$widget_design, 'display'), $widget_args );
     324               
    305325        }
    306326
    307327        function update( $new_instance, $old_instance ) {
     
    334354
    335355        function widget( $args, $instance ) {
    336356                extract($args);
    337                 $title = apply_filters('widget_title', empty($instance['title']) ? '&nbsp;' : $instance['title']);
    338                 echo $before_widget;
    339                 if ( $title )
    340                         echo $before_title . $title . $after_title;
    341                 echo '<div id="calendar_wrap">';
    342                 get_calendar();
    343                 echo '</div>';
    344                 echo $after_widget;
     357                $title = apply_filters('widget_title', empty($instance['title']) ? __('Calendar') : $instance['title']);
     358               
     359                $widget_design = apply_filters( 'widget_design', new Widget_Basic);
     360                $widget_array = array(
     361                        'title'                 => $title,
     362                        'before_output' => "<div id='calendar_wrap'>",
     363                        'output'                => get_calendar(true, false),
     364                        'after_output'  => "</div>",
     365                        'style'                 => "none"
     366                );
     367                $widget_args = array(array_merge($args, $widget_array));
     368               
     369                echo call_user_func_array( array(&$widget_design, 'display'), $widget_args );
     370
    345371        }
    346372
    347373        function update( $new_instance, $old_instance ) {
     
    378404                extract($args);
    379405                $title = apply_filters( 'widget_title', empty($instance['title']) ? '' : $instance['title'], $instance );
    380406                $text = apply_filters( 'widget_text', $instance['text'], $instance );
    381                 echo $before_widget;
    382                 if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?>
    383                         <div class="textwidget"><?php echo $instance['filter'] ? wpautop($text) : $text; ?></div>
    384                 <?php
    385                 echo $after_widget;
     407               
     408                $widget_design = apply_filters( 'widget_design', new Widget_Basic);
     409                $widget_array = array(
     410                        'title'                 => $title,
     411                        'before_output' => "<div class='textwidget'>",
     412                        'output'                => $instance['filter'] ? wpautop($text) : $text,
     413                        'after_output'  => "</div>",
     414                        'style'                 => "none"
     415                );
     416                $widget_args = array(array_merge($args, $widget_array));
     417               
     418                echo call_user_func_array( array(&$widget_design, 'display'), $widget_args );
     419
    386420        }
    387421
    388422        function update( $new_instance, $old_instance ) {
     
    430464                $c = $instance['count'] ? '1' : '0';
    431465                $h = $instance['hierarchical'] ? '1' : '0';
    432466                $d = $instance['dropdown'] ? '1' : '0';
     467                $walker = empty( $instance['walker'] ) ? '' : $instance['walker'];
     468               
     469                if (  !empty( $walker ) )
     470                        $cat_walker = new $walker;
     471               
     472                $cat_args = array('echo' => 0, 'orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h, 'walker' => $cat_walker);
    433473
    434                 echo $before_widget;
    435                 if ( $title )
    436                         echo $before_title . $title . $after_title;
    437 
    438                 $cat_args = array('orderby' => 'name', 'show_count' => $c, 'hierarchical' => $h);
    439 
    440474                if ( $d ) {
    441475                        $cat_args['show_option_none'] = __('Select Category');
    442                         wp_dropdown_categories(apply_filters('widget_categories_dropdown_args', $cat_args));
    443 ?>
     476                        $widget_opt_array = array('style' => "none");
     477                        $output .= wp_dropdown_categories(apply_filters('widget_categories_dropdown_args', $cat_args));
     478                        $output .= "<script type='text/javascript'>
     479                        /* <![CDATA[ */
     480                                var dropdown = document.getElementById(\"cat\");
     481                                function onCatChange() {
     482                                        if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
     483                                                location.href = \"" . get_option('home') . "/?cat=\"+dropdown.options[dropdown.selectedIndex].value;
     484                                        }
     485                                }
     486                                dropdown.onchange = onCatChange;
     487                        /* ]]> */
     488                        </script>";
    444489
    445 <script type='text/javascript'>
    446 /* <![CDATA[ */
    447         var dropdown = document.getElementById("cat");
    448         function onCatChange() {
    449                 if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
    450                         location.href = "<?php echo get_option('home'); ?>/?cat="+dropdown.options[dropdown.selectedIndex].value;
    451                 }
    452         }
    453         dropdown.onchange = onCatChange;
    454 /* ]]> */
    455 </script>
    456 
    457 <?php
    458490                } else {
    459 ?>
    460                 <ul>
    461 <?php
    462                 $cat_args['title_li'] = '';
    463                 wp_list_categories(apply_filters('widget_categories_args', $cat_args));
    464 ?>
    465                 </ul>
    466 <?php
     491                               
     492                        $cat_args['title_li'] = '';
     493                        $widget_opt_array = array('before_output' => "<ul>", 'after_output' => "</ul>", 'style' => "li");
     494                        $output = wp_list_categories(apply_filters('widget_categories_args', $cat_args));
     495                       
    467496                }
    468497
    469                 echo $after_widget;
     498                $widget_design = apply_filters( 'widget_design', new Widget_Basic);
     499                $widget_array = array(
     500                        'title'                 => $title,
     501                        'output'                => $output
     502                );
     503                $widget_args = array(array_merge($args, array_merge($widget_array, $widget_opt_array)));
     504               
     505                echo call_user_func_array( array(&$widget_design, 'display'), $widget_args );
     506               
    470507        }
    471508
    472509        function update( $new_instance, $old_instance ) {
     
    475512                $instance['count'] = $new_instance['count'] ? 1 : 0;
    476513                $instance['hierarchical'] = $new_instance['hierarchical'] ? 1 : 0;
    477514                $instance['dropdown'] = $new_instance['dropdown'] ? 1 : 0;
     515                $instance['walker'] = strip_tags( $new_instance['walker'] );
    478516
    479517                return $instance;
    480518        }
    481519
    482520        function form( $instance ) {
    483521                //Defaults
    484                 $instance = wp_parse_args( (array) $instance, array( 'title' => '') );
     522                $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'walker' => '') );
    485523                $title = esc_attr( $instance['title'] );
    486524                $count = isset($instance['count']) ? (bool) $instance['count'] :false;
    487525                $hierarchical = isset( $instance['hierarchical'] ) ? (bool) $instance['hierarchical'] : false;
    488526                $dropdown = isset( $instance['dropdown'] ) ? (bool) $instance['dropdown'] : false;
     527                $walker = esc_attr( $instance['walker'] );
    489528?>
    490529                <p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e( 'Title:' ); ?></label>
    491530                <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo $title; ?>" /></p>
     
    497536                <label for="<?php echo $this->get_field_id('count'); ?>"><?php _e( 'Show post counts' ); ?></label><br />
    498537
    499538                <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id('hierarchical'); ?>" name="<?php echo $this->get_field_name('hierarchical'); ?>"<?php checked( $hierarchical ); ?> />
    500                 <label for="<?php echo $this->get_field_id('hierarchical'); ?>"><?php _e( 'Show hierarchy' ); ?></label></p>
     539                <label for="<?php echo $this->get_field_id('hierarchical'); ?>"><?php _e( 'Show hierarchy' ); ?></label>
     540               
     541                <br /><br />
     542                <label for="<?php echo $this->get_field_id('walker'); ?>"><?php _e( 'Walker:' ); ?></label> <input type="text" value="<?php echo $walker; ?>" name="<?php echo $this->get_field_name('walker'); ?>" id="<?php echo $this->get_field_id('walker'); ?>" class="widefat" />
     543                <br />
     544                <small><?php _e( 'Customer Walker' ); ?></small></p>
    501545<?php
    502546        }
    503547
     
    543587                        $number = 15;
    544588
    545589                $r = new WP_Query(array('showposts' => $number, 'nopaging' => 0, 'post_status' => 'publish', 'caller_get_posts' => 1));
     590               
    546591                if ($r->have_posts()) :
    547 ?>
    548                 <?php echo $before_widget; ?>
    549                 <?php if ( $title ) echo $before_title . $title . $after_title; ?>
    550                 <ul>
    551                 <?php  while ($r->have_posts()) : $r->the_post(); ?>
    552                 <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>
    553                 <?php endwhile; ?>
    554                 </ul>
    555                 <?php echo $after_widget; ?>
    556 <?php
     592               
     593                        while ($r->have_posts()) {
     594                                $r->the_post();
     595                                $posts_output .= "<li><a href='" . get_permalink() . "' title='" . esc_attr(get_the_title() ? get_the_title() : get_the_ID()) . "'>" .  ( ( get_the_title() ) ? get_the_title() : the_ID() ) . "</a></li>";
     596                        }
     597                       
    557598                        wp_reset_query();  // Restore global post data stomped by the_post().
     599               
    558600                endif;
    559601
     602                $widget_design = apply_filters( 'widget_design', new Widget_Recent_Posts);
     603                $widget_array = array(
     604                        'title'                 => $title,
     605                        'before_output' => "<ul>",
     606                        'output'                => $posts_output,
     607                        'after_output'  => "</ul>",
     608                        'style'                 => "li"
     609                );
     610                $widget_args = array(array_merge($args, $widget_array));
     611               
     612                echo call_user_func_array( array(&$widget_design, 'display'), $widget_args );
     613               
    560614                $cache[$args['widget_id']] = ob_get_flush();
    561615                wp_cache_add('widget_recent_posts', $cache, 'widget');
     616               
    562617        }
    563618
    564619        function update( $new_instance, $old_instance ) {
     
    639694                }
    640695
    641696                $comments = array_slice( (array) $comments, 0, $number );
    642 ?>
    643                 <?php echo $before_widget; ?>
    644                         <?php if ( $title ) echo $before_title . $title . $after_title; ?>
    645                         <ul id="recentcomments"><?php
    646                         if ( $comments ) : foreach ( (array) $comments as $comment) :
    647                         echo  '<li class="recentcomments">' . /* translators: comments widget: 1: comment author, 2: post link */ sprintf(_x('%1$s on %2$s', 'widgets'), get_comment_author_link(), '<a href="' . esc_url( get_comment_link($comment->comment_ID) ) . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>';
    648                         endforeach; endif;?></ul>
    649                 <?php echo $after_widget; ?>
    650 <?php
     697               
     698                if ( $comments ) : foreach ( (array) $comments as $comment) :
     699                        $comments_output .=  '<li class="recentcomments">' . /* translators: comments widget: 1: comment author, 2: post link */ sprintf(_x('%1$s on %2$s', 'widgets'), get_comment_author_link(), '<a href="' . esc_url( get_comment_link($comment->comment_ID) ) . '">' . get_the_title($comment->comment_post_ID) . '</a>') . '</li>';
     700                endforeach; endif;
     701               
     702                $widget_design = apply_filters( 'widget_design', new Widget_Basic);
     703                $widget_array = array(
     704                        'title'                 => $title,
     705                        'before_output' => "<ul id='recentcomments'>",
     706                        'output'                => $comments_output,
     707                        'after_output'  => "</ul>",
     708                        'style'                 => "li"
     709                );
     710                $widget_args = array(array_merge($args, $widget_array));
     711               
     712                echo call_user_func_array( array(&$widget_design, 'display'), $widget_args );
     713               
    651714        }
    652715
    653716        function update( $new_instance, $old_instance ) {
     
    720783
    721784                if ( empty($title) )
    722785                        $title = empty($desc) ? __('Unknown Feed') : $desc;
    723 
     786               
    724787                $title = apply_filters('widget_title', $title );
    725788                $url = esc_url(strip_tags($url));
    726789                $icon = includes_url('images/rss.png');
    727790                if ( $title )
    728791                        $title = "<a class='rsswidget' href='$url' title='" . esc_attr(__('Syndicate this content')) ."'><img style='background:orange;color:white;border:none;' width='14' height='14' src='$icon' alt='RSS' /></a> <a class='rsswidget' href='$link' title='$desc'>$title</a>";
    729 
    730                 echo $before_widget;
    731                 if ( $title )
    732                         echo $before_title . $title . $after_title;
    733                 wp_widget_rss_output( $rss, $instance );
    734                 echo $after_widget;
     792               
     793                $widget_design = apply_filters( 'widget_design', new Widget_Basic);
     794                $widget_func_array = array_merge($instance, array('echo' => 0));
     795                $widget_array = array(
     796                        'title'                 => $title,
     797                        'before_output' => "<ul>",
     798                        'output'                => wp_widget_rss_output( $rss, $widget_func_array ),
     799                        'after_output'  => "</ul>",
     800                        'style'                 => "li"
     801                );
     802                $widget_args = array(array_merge($args, $widget_array));
     803               
     804                echo call_user_func_array( array(&$widget_design, 'display'), $widget_args );
     805               
    735806                $rss->__destruct();
    736807                unset($rss);
    737808        }
     
    760831 * @param array $args Widget arguments.
    761832 */
    762833function wp_widget_rss_output( $rss, $args = array() ) {
     834       
     835        $rss_items = '';
     836       
    763837        if ( is_string( $rss ) ) {
    764838                $rss = fetch_feed($rss);
    765839        } elseif ( is_array($rss) && isset($rss['url']) ) {
     
    771845
    772846        if ( is_wp_error($rss) ) {
    773847                if ( is_admin() || current_user_can('manage_options') )
    774                         echo '<p>' . sprintf( __('<strong>RSS Error</strong>: %s'), $rss->get_error_message() ) . '</p>';
     848                        $rss_items .= '<p>' . sprintf( __('<strong>RSS Error</strong>: %s'), $rss->get_error_message() ) . '</p>';
    775849                return;
    776850        }
    777851
    778         $default_args = array( 'show_author' => 0, 'show_date' => 0, 'show_summary' => 0 );
     852        $default_args = array( 'show_author' => 0, 'show_date' => 0, 'show_summary' => 0, 'echo' => 1 );
    779853        $args = wp_parse_args( $args, $default_args );
    780854        extract( $args, EXTR_SKIP );
    781855
     
    787861        $show_date     = (int) $show_date;
    788862
    789863        if ( !$rss->get_item_quantity() ) {
    790                 echo '<ul><li>' . __( 'An error has occurred; the feed is probably down. Try again later.' ) . '</li></ul>';
     864                $rss_items .= '<ul><li>' . __( 'An error has occurred; the feed is probably down. Try again later.' ) . '</li></ul>';
    791865                $rss->__destruct();
    792866                unset($rss);
    793867                return;
    794868        }
    795869
    796         echo '<ul>';
    797870        foreach ( $rss->get_items(0, $items) as $item ) {
    798871                $link = $item->get_link();
    799872                while ( stristr($link, 'http') != $link )
     
    835908                }
    836909
    837910                if ( $link == '' ) {
    838                         echo "<li>$title{$date}{$summary}{$author}</li>";
     911                        $rss_items .= "<li>$title{$date}{$summary}{$author}</li>";
    839912                } else {
    840                         echo "<li><a class='rsswidget' href='$link' title='$desc'>$title</a>{$date}{$summary}{$author}</li>";
     913                        $rss_items .= "<li><a class='rsswidget' href='$link' title='$desc'>$title</a>{$date}{$summary}{$author}</li>";
    841914                }
    842915        }
    843         echo '</ul>';
     916       
     917        if ( $echo )
     918                echo $rss_items;
     919        else
     920                return $rss_items;
     921       
    844922        $rss->__destruct();
    845923        unset($rss);
    846924}
     
    9761054                extract($args);
    9771055                $title = apply_filters('widget_title', empty($instance['title']) ? __('Tags') : $instance['title']);
    9781056
    979                 echo $before_widget;
    980                 if ( $title )
    981                         echo $before_title . $title . $after_title;
    982                 echo '<div>';
    983                 wp_tag_cloud(apply_filters('widget_tag_cloud_args', array()));
    984                 echo "</div>\n";
    985                 echo $after_widget;
     1057                $widget_design = apply_filters( 'widget_design', new Widget_Basic);
     1058                $widget_array = array(
     1059                        'title'                 => $title,
     1060                        'before_output' => "<div>",
     1061                        'output'                => wp_tag_cloud(apply_filters('widget_tag_cloud_args', array('echo' => 0))),
     1062                        'after_output'  => "</div>",
     1063                        'style'                 => "none"
     1064                );
     1065                $widget_args = array(array_merge($args, $widget_array));
     1066               
     1067                echo call_user_func_array( array(&$widget_design, 'display'), $widget_args );
     1068               
    9861069        }
    9871070
    9881071        function update( $new_instance, $old_instance ) {
     
    9981081        }
    9991082}
    10001083
     1084class Walker_Widget {
     1085       
     1086        function start_widget($args, &$output)  {}
     1087       
     1088        function end_widget($args, &$output)            {}
     1089       
     1090        function title_widget($args, &$output)  {}
     1091       
     1092        function content_widget($args, &$output)        {}
     1093
     1094        function display( $args = array() ) {
     1095                $output = '';
     1096                call_user_func_array( array(&$this, 'start_widget'),    array($args, &$output) );
     1097                call_user_func_array( array(&$this, 'title_widget'),    array($args, &$output) );
     1098                call_user_func_array( array(&$this, 'content_widget'),  array($args, &$output) );
     1099                call_user_func_array( array(&$this, 'end_widget'),              array($args, &$output) );
     1100                return $output;
     1101        }
     1102       
     1103}
     1104
     1105class Widget_Basic extends Walker_Widget {
     1106       
     1107        function start_widget($args, &$output) {
     1108                $output .= "<li>";             
     1109        }
     1110       
     1111        function title_widget($args, &$output) {
     1112                $output .= "<h2>" . $args['title'] . "</h2>";
     1113        }
     1114               
     1115        function content_widget($args, &$output) {
     1116                $output .= $args['before_output'] . $args['output'] . $args['after_output'];
     1117        }
     1118       
     1119        function end_widget($args, &$output) {
     1120                $output .= "</li>";
     1121        }
     1122       
     1123}
     1124
     1125class Widget_Tag_Cloud extends Walker_Widget {
     1126       
     1127        function title_widget($args, &$output) {
     1128                $output .= "<h2>" . $args['title'] . "</h2>";
     1129        }
     1130               
     1131        function content_widget($args, &$output) {
     1132                $output .= $args['before_output'] . $args['output'] . $args['after_output'];
     1133        }
     1134       
     1135}
     1136
     1137class Widget_Search extends Walker_Widget {
     1138
     1139        function title_widget($args, &$output) {
     1140                $output .= $args['title'];
     1141        }
     1142               
     1143        function content_widget($args, &$output) {
     1144                $output .= $args['output'];
     1145        }
     1146       
     1147}
     1148
     1149class Widget_Recent_Posts extends Walker_Widget {
     1150       
     1151        function start_widget($args, &$output) {
     1152                $output .= sprintf( __("<li id='%s' class='widget %s'>"), $args['widget_id'], $args['classname'] );
     1153        }
     1154       
     1155        function title_widget($args, &$output) {
     1156                $output .= "<h2>" . $args['title'] . "</h2>";
     1157        }
     1158               
     1159        function content_widget($args, &$output) {
     1160                $output .= $args['before_output'] . $args['output'] . $args['after_output'];
     1161        }
     1162       
     1163        function end_widget($args, &$output) {
     1164                $output .= "</li>";
     1165        }
     1166       
     1167}
     1168
    10011169/**
    10021170 * Register all of the default WordPress widgets on startup.
    10031171 *
  • wp-includes/general-template.php

     
    112112 *
    113113 * @since 2.7.0
    114114 */
    115 function get_search_form() {
     115function get_search_form($echo = true) {
    116116        do_action( 'get_search_form' );
    117117
    118118        $search_form_template = locate_template(array('searchform.php'));
     
    128128        </div>
    129129        </form>';
    130130
    131         echo apply_filters('get_search_form', $form);
     131        if ( $echo )
     132                echo apply_filters('get_search_form', $form);
     133        else
     134                return apply_filters('get_search_form', $form);
    132135}
    133136
    134137/**
     
    141144 * @uses apply_filters() Calls 'loginout' hook on HTML link content.
    142145 *
    143146 * @param string $redirect Optional path to redirect to on login/logout.
     147 * @param boolean $echo Default to echo and not return the link.
    144148 */
    145 function wp_loginout($redirect = '') {
     149function wp_loginout($redirect = '', $echo = true) {
    146150        if ( ! is_user_logged_in() )
    147151                $link = '<a href="' . esc_url( wp_login_url($redirect) ) . '">' . __('Log in') . '</a>';
    148152        else
    149153                $link = '<a href="' . esc_url( wp_logout_url($redirect) ) . '">' . __('Log out') . '</a>';
    150 
    151         echo apply_filters('loginout', $link);
     154       
     155        if ( $echo )
     156                echo apply_filters('loginout', $link);
     157        else
     158                return apply_filters('loginout', $link);
    152159}
    153160
    154161/**
     
    228235 *
    229236 * @param string $before Text to output before the link (defaults to <li>).
    230237 * @param string $after Text to output after the link (defaults to </li>).
     238 * @param boolean $echo Default to echo and not return the link.
    231239 */
    232 function wp_register( $before = '<li>', $after = '</li>' ) {
     240function wp_register( $before = '<li>', $after = '</li>', $echo = true ) {
    233241
    234242        if ( ! is_user_logged_in() ) {
    235243                if ( get_option('users_can_register') )
     
    239247        } else {
    240248                $link = $before . '<a href="' . admin_url() . '">' . __('Site Admin') . '</a>' . $after;
    241249        }
    242 
    243         echo apply_filters('register', $link);
     250       
     251        if ( $echo )
     252                echo apply_filters('register', $link);
     253        else
     254                return apply_filters('register', $link);
    244255}
    245256
    246257/**
     
    952963 * @since 1.0.0
    953964 *
    954965 * @param bool $initial Optional, default is true. Use initial calendar names.
     966 * @param bool $echo Optional, default is true. Set to false for return.
    955967 */
    956 function get_calendar($initial = true) {
     968function get_calendar($initial = true, $echo = true) {
    957969        global $wpdb, $m, $monthnum, $year, $wp_locale, $posts;
    958970
    959971        $cache = array();
     
    10241036
    10251037        /* translators: Calendar caption: 1: month name, 2: 4-digit year */
    10261038        $calendar_caption = _x('%1$s %2$s', 'calendar caption');
    1027         echo '<table id="wp-calendar" summary="' . esc_attr__('Calendar') . '">
     1039        $calendar_output .= '<table id="wp-calendar" summary="' . esc_attr__('Calendar') . '">
    10281040        <caption>' . sprintf($calendar_caption, $wp_locale->get_month($thismonth), date('Y', $unixmonth)) . '</caption>
    10291041        <thead>
    10301042        <tr>';
     
    10381050        foreach ( $myweek as $wd ) {
    10391051                $day_name = (true == $initial) ? $wp_locale->get_weekday_initial($wd) : $wp_locale->get_weekday_abbrev($wd);
    10401052                $wd = esc_attr($wd);
    1041                 echo "\n\t\t<th abbr=\"$wd\" scope=\"col\" title=\"$wd\">$day_name</th>";
     1053                $calendar_output .= "\n\t\t<th abbr=\"$wd\" scope=\"col\" title=\"$wd\">$day_name</th>";
    10421054        }
    10431055
    1044         echo '
     1056        $calendar_output .= '
    10451057        </tr>
    10461058        </thead>
    10471059
     
    10491061        <tr>';
    10501062
    10511063        if ( $previous ) {
    1052                 echo "\n\t\t".'<td abbr="' . $wp_locale->get_month($previous->month) . '" colspan="3" id="prev"><a href="' .
     1064                $calendar_output .= "\n\t\t".'<td abbr="' . $wp_locale->get_month($previous->month) . '" colspan="3" id="prev"><a href="' .
    10531065                get_month_link($previous->year, $previous->month) . '" title="' . sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($previous->month),
    10541066                        date('Y', mktime(0, 0 , 0, $previous->month, 1, $previous->year))) . '">&laquo; ' . $wp_locale->get_month_abbrev($wp_locale->get_month($previous->month)) . '</a></td>';
    10551067        } else {
    1056                 echo "\n\t\t".'<td colspan="3" id="prev" class="pad">&nbsp;</td>';
     1068                $calendar_output .= "\n\t\t".'<td colspan="3" id="prev" class="pad">&nbsp;</td>';
    10571069        }
    10581070
    1059         echo "\n\t\t".'<td class="pad">&nbsp;</td>';
     1071        $calendar_output .= "\n\t\t".'<td class="pad">&nbsp;</td>';
    10601072
    10611073        if ( $next ) {
    1062                 echo "\n\t\t".'<td abbr="' . $wp_locale->get_month($next->month) . '" colspan="3" id="next"><a href="' .
     1074                $calendar_output .= "\n\t\t".'<td abbr="' . $wp_locale->get_month($next->month) . '" colspan="3" id="next"><a href="' .
    10631075                get_month_link($next->year, $next->month) . '" title="' . esc_attr( sprintf(__('View posts for %1$s %2$s'), $wp_locale->get_month($next->month) ,
    10641076                        date('Y', mktime(0, 0 , 0, $next->month, 1, $next->year))) ) . '">' . $wp_locale->get_month_abbrev($wp_locale->get_month($next->month)) . ' &raquo;</a></td>';
    10651077        } else {
    1066                 echo "\n\t\t".'<td colspan="3" id="next" class="pad">&nbsp;</td>';
     1078                $calendar_output .= "\n\t\t".'<td colspan="3" id="next" class="pad">&nbsp;</td>';
    10671079        }
    10681080
    1069         echo '
     1081        $calendar_output .= '
    10701082        </tr>
    10711083        </tfoot>
    10721084
     
    11181130        // See how much we should pad in the beginning
    11191131        $pad = calendar_week_mod(date('w', $unixmonth)-$week_begins);
    11201132        if ( 0 != $pad )
    1121                 echo "\n\t\t".'<td colspan="'. esc_attr($pad) .'" class="pad">&nbsp;</td>';
     1133                $calendar_output .= "\n\t\t".'<td colspan="'. esc_attr($pad) .'" class="pad">&nbsp;</td>';
    11221134
    11231135        $daysinmonth = intval(date('t', $unixmonth));
    11241136        for ( $day = 1; $day <= $daysinmonth; ++$day ) {
    11251137                if ( isset($newrow) && $newrow )
    1126                         echo "\n\t</tr>\n\t<tr>\n\t\t";
     1138                        $calendar_output .= "\n\t</tr>\n\t<tr>\n\t\t";
    11271139                $newrow = false;
    11281140
    11291141                if ( $day == gmdate('j', (time() + (get_option('gmt_offset') * 3600))) && $thismonth == gmdate('m', time()+(get_option('gmt_offset') * 3600)) && $thisyear == gmdate('Y', time()+(get_option('gmt_offset') * 3600)) )
    1130                         echo '<td id="today">';
     1142                        $calendar_output .= '<td id="today">';
    11311143                else
    1132                         echo '<td>';
     1144                        $calendar_output .= '<td>';
    11331145
    11341146                if ( in_array($day, $daywithpost) ) // any posts today?
    1135                                 echo '<a href="' . get_day_link($thisyear, $thismonth, $day) . "\" title=\"" . esc_attr($ak_titles_for_day[$day]) . "\">$day</a>";
     1147                                $calendar_output .= '<a href="' . get_day_link($thisyear, $thismonth, $day) . "\" title=\"" . esc_attr($ak_titles_for_day[$day]) . "\">$day</a>";
    11361148                else
    1137                         echo $day;
    1138                 echo '</td>';
     1149                        $calendar_output .= $day;
     1150                $calendar_output .= '</td>';
    11391151
    11401152                if ( 6 == calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins) )
    11411153                        $newrow = true;
     
    11431155
    11441156        $pad = 7 - calendar_week_mod(date('w', mktime(0, 0 , 0, $thismonth, $day, $thisyear))-$week_begins);
    11451157        if ( $pad != 0 && $pad != 7 )
    1146                 echo "\n\t\t".'<td class="pad" colspan="'. esc_attr($pad) .'">&nbsp;</td>';
     1158                $calendar_output .= "\n\t\t".'<td class="pad" colspan="'. esc_attr($pad) .'">&nbsp;</td>';
    11471159
    1148         echo "\n\t</tr>\n\t</tbody>\n\t</table>";
     1160        $calendar_output .= "\n\t</tr>\n\t</tbody>\n\t</table>";
    11491161
    11501162        $output = ob_get_contents();
    11511163        ob_end_clean();
    1152         echo $output;
    11531164        $cache[ $key ] = $output;
    11541165        wp_cache_set( 'get_calendar', $cache, 'calendar' );
     1166
     1167        if ( $echo )
     1168                echo $calendar_output;
     1169        else
     1170                return $calendar_output;
     1171
    11551172}
    11561173
    11571174/**
  • wp-includes/widgets.php

     
    548548        $defaults = array(
    549549                'name' => sprintf(__('Sidebar %d'), $i ),
    550550                'id' => "sidebar-$i",
    551                 'description' => '',
    552                 'before_widget' => '<li id="%1$s" class="widget %2$s">',
    553                 'after_widget' => "</li>\n",
    554                 'before_title' => '<h2 class="widgettitle">',
    555                 'after_title' => "</h2>\n",
     551                'description' => ''
    556552        );
    557553
    558554        $sidebar = array_merge($defaults, (array) $args);
     
    873869                                $classname_ .= '_' . get_class($cn);
    874870                }
    875871                $classname_ = ltrim($classname_, '_');
    876                 $params[0]['before_widget'] = sprintf($params[0]['before_widget'], $id, $classname_);
     872                $params[0]['classname'] = $classname_;
    877873
    878874                $params = apply_filters( 'dynamic_sidebar_params', $params );
    879875
     
    12921288        if ( !is_a($widget_obj, 'WP_Widget') )
    12931289                return;
    12941290
    1295         $before_widget = sprintf('<div class="widget %s">', $widget_obj->widget_options['classname']);
    1296         $default_args = array('before_widget' => $before_widget, 'after_widget' => "</div>", 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>');
    1297 
    1298         $args = wp_parse_args($args, $default_args);
    12991291        $instance = wp_parse_args($instance);
    13001292
    13011293        $widget_obj->_set(-1);