Make WordPress Core

Ticket #10948: 10948.2.diff

File 10948.2.diff, 4.7 KB (added by MikeLittle, 12 years ago)

Going with the first option -- make comment walker behave like the others -- (a.k.a my original approach) the attached patch adds use of $output throughout the class. It also wraps the two instances of user callbacks with output buffering, and adds the output parameter and output buffering to the new ping(), comment(), and html5_comment() functions. Autodocs also updated.

  • wp-includes/comment-template.php

     
    12441244                        case 'div':
    12451245                                break;
    12461246                        case 'ol':
    1247                                 echo '<ol class="children">' . "\n";
     1247                                $output .= '<ol class="children">' . "\n";
    12481248                                break;
    12491249                        default:
    12501250                        case 'ul':
    1251                                 echo '<ul class="children">' . "\n";
     1251                                $output .= '<ul class="children">' . "\n";
    12521252                                break;
    12531253                }
    12541254        }
     
    12681268                        case 'div':
    12691269                                break;
    12701270                        case 'ol':
    1271                                 echo "</ol><!-- .children -->\n";
     1271                                $output .= "</ol><!-- .children -->\n";
    12721272                                break;
    12731273                        default:
    12741274                        case 'ul':
    1275                                 echo "</ul><!-- .children -->\n";
     1275                                $output .= "</ul><!-- .children -->\n";
    12761276                                break;
    12771277                }
    12781278        }
     
    13311331                $GLOBALS['comment'] = $comment;
    13321332
    13331333                if ( !empty( $args['callback'] ) ) {
     1334                        ob_start();
    13341335                        call_user_func( $args['callback'], $comment, $args, $depth );
     1336                        $output .= ob_get_clean();
    13351337                        return;
    13361338                }
    13371339
    13381340                if ( ( 'pingback' == $comment->comment_type || 'trackback' == $comment->comment_type ) && $args['short_ping'] ) {
    1339                         $this->ping( $comment, $depth, $args );
     1341                        $this->ping( $output, $comment, $depth, $args );
    13401342                } elseif ( 'html5' === $args['format'] ) {
    1341                         $this->html5_comment( $comment, $depth, $args );
     1343                        $this->html5_comment( $output, $comment, $depth, $args );
    13421344                } else {
    1343                         $this->comment( $comment, $depth, $args );
     1345                        $this->comment( $output, $comment, $depth, $args );
    13441346                }
    13451347        }
    13461348
     
    13551357         */
    13561358        function end_el( &$output, $comment, $depth = 0, $args = array() ) {
    13571359                if ( !empty( $args['end-callback'] ) ) {
     1360                        ob_start();
    13581361                        call_user_func( $args['end-callback'], $comment, $args, $depth );
     1362                        $output .= ob_get_clean();
    13591363                        return;
    13601364                }
    13611365                if ( 'div' == $args['style'] )
    1362                         echo "</div><!-- #comment-## -->\n";
     1366                        $output .= "</div><!-- #comment-## -->\n";
    13631367                else
    1364                         echo "</li><!-- #comment-## -->\n";
     1368                        $output .= "</li><!-- #comment-## -->\n";
    13651369        }
    13661370
    13671371        /**
    13681372         * @since 3.6
    13691373         * @access protected
    13701374         *
     1375         * @param string $output Passed by reference. Used to append additional content.
    13711376         * @param object $comment
    13721377         * @param int $depth Depth of comment.
    13731378         * @param array $args
    13741379         */
    1375         protected function ping( $comment, $depth, $args ) {
     1380        protected function ping( &$output, $comment, $depth, $args ) {
    13761381                $tag = ( 'div' == $args['style'] ) ? 'div' : 'li';
     1382                ob_start();
    13771383?>
    13781384                <<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class(); ?>>
    13791385                        <div class="comment-body">
    13801386                                <?php _e( 'Pingback:' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?>
    13811387                        </div>
    13821388<?php
     1389                $output .= ob_get_clean();
    13831390        }
    13841391
    13851392        /**
    13861393         * @since 3.6
    13871394         * @access protected
    13881395         *
     1396         * @param string $output Passed by reference. Used to append additional content.
    13891397         * @param object $comment Comment to display.
    13901398         * @param int $depth Depth of comment.
    13911399         * @param array $args Optional args.
    13921400         */
    1393         protected function comment( $comment, $depth, $args ) {
     1401        protected function comment( &$output, $comment, $depth, $args ) {
     1402                ob_start();
    13941403                if ( 'div' == $args['style'] ) {
    13951404                        $tag = 'div';
    13961405                        $add_below = 'comment';
     
    14281437                </div>
    14291438                <?php endif; ?>
    14301439<?php
     1440                $output .= ob_get_clean();
    14311441        }
    14321442
    14331443        /**
    14341444         * @since 3.6
    14351445         * @access protected
    14361446         *
     1447         * @param string $output Passed by reference. Used to append additional content.
    14371448         * @param object $comment Comment to display.
    14381449         * @param int $depth Depth of comment.
    14391450         * @param array $args Optional args.
    14401451         */
    1441         protected function html5_comment( $comment, $depth, $args ) {
     1452        protected function html5_comment( &$output, $comment, $depth, $args ) {
    14421453                $tag = ( 'div' === $args['style'] ) ? 'div' : 'li';
     1454                ob_start();
    14431455?>
    14441456                <<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?>>
    14451457                        <article id="div-comment-<?php comment_ID(); ?>" class="comment-body">
     
    14721484                                </div><!-- .reply -->
    14731485                        </article><!-- .comment-body -->
    14741486<?php
     1487                $output .= ob_get_clean();
    14751488        }
    14761489}
    14771490
     
    15081521                'reverse_children'  => '',
    15091522                'format'            => current_theme_supports( 'html5', 'comment-list' ) ? 'html5' : 'xhtml',
    15101523                'short_ping'        => false,
     1524                'echo'                          => true,
    15111525        );
    15121526
    15131527        $r = wp_parse_args( $args, $defaults );
     
    15761590        if ( empty($walker) )
    15771591                $walker = new Walker_Comment;
    15781592
    1579         $walker->paged_walk($_comments, $max_depth, $page, $per_page, $r);
     1593        $output = $walker->paged_walk($_comments, $max_depth, $page, $per_page, $r);
    15801594        $wp_query->max_num_comment_pages = $walker->max_pages;
    15811595
    15821596        $in_comment_loop = false;
     1597
     1598        if ( $r['echo'] )
     1599                echo $output;
     1600        else
     1601                return $output;
    15831602}
    15841603
    15851604/**