Make WordPress Core


Ignore:
Timestamp:
03/14/2013 04:26:04 AM (11 years ago)
Author:
markjaquith
Message:

Improve wp_list_comments() markup.

  • Whitespace cleanup
  • Accepts format=html5 which uses some of the HTML5 elements
  • Some helpful HTML comments to help untangle the HTML
  • Other misc code cleanup

props lancewillett, obenland, georgestephanis. fixes #20088.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/comment-template.php

    r23689 r23694  
    12451245                break;
    12461246            case 'ol':
    1247                 echo "<ol class='children'>\n";
     1247                echo '<ol class="children">' . "\n";
    12481248                break;
    12491249            default:
    12501250            case 'ul':
    1251                 echo "<ul class='children'>\n";
     1251                echo '<ul class="children">' . "\n";
    12521252                break;
    12531253        }
     
    12691269                break;
    12701270            case 'ol':
    1271                 echo "</ol>\n";
     1271                echo "</ol><!-- .children -->\n";
    12721272                break;
    12731273            default:
    12741274            case 'ul':
    1275                 echo "</ul>\n";
     1275                echo "</ul><!-- .children -->\n";
    12761276                break;
    12771277        }
     
    13311331        $GLOBALS['comment'] = $comment;
    13321332
    1333         if ( !empty($args['callback']) ) {
    1334             call_user_func($args['callback'], $comment, $args, $depth);
     1333        if ( !empty( $args['callback'] ) ) {
     1334            call_user_func( $args['callback'], $comment, $args, $depth );
    13351335            return;
    13361336        }
    13371337
    1338         extract($args, EXTR_SKIP);
    1339 
    1340         if ( 'div' == $args['style'] ) {
    1341             $tag = 'div';
    1342             $add_below = 'comment';
     1338        if ( ( 'pingback' == $comment->comment_type || 'trackback' == $comment->comment_type ) && $args['short_ping'] ) {
     1339            $this->ping( $comment, $depth, $args );
     1340        } elseif ( 'html5' === $args['format'] ) {
     1341            $this->html5_comment( $comment, $depth, $args );
    13431342        } else {
    1344             $tag = 'li';
    1345             $add_below = 'div-comment';
     1343            $this->comment( $comment, $depth, $args );
    13461344        }
    1347 ?>
    1348         <<?php echo $tag ?> <?php comment_class(empty( $args['has_children'] ) ? '' : 'parent') ?> id="comment-<?php comment_ID() ?>">
    1349         <?php if ( 'div' != $args['style'] ) : ?>
    1350         <div id="div-comment-<?php comment_ID() ?>" class="comment-body">
    1351         <?php endif; ?>
    1352         <div class="comment-author vcard">
    1353         <?php if ($args['avatar_size'] != 0) echo get_avatar( $comment, $args['avatar_size'] ); ?>
    1354         <?php printf(__('<cite class="fn">%s</cite> <span class="says">says:</span>'), get_comment_author_link()) ?>
    1355         </div>
    1356 <?php if ($comment->comment_approved == '0') : ?>
    1357         <em class="comment-awaiting-moderation"><?php _e('Your comment is awaiting moderation.') ?></em>
    1358         <br />
    1359 <?php endif; ?>
    1360 
    1361         <div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>">
    1362             <?php
    1363                 /* translators: 1: date, 2: time */
    1364                 printf( __('%1$s at %2$s'), get_comment_date(),  get_comment_time()) ?></a><?php edit_comment_link(__('(Edit)'),'&nbsp;&nbsp;','' );
    1365             ?>
    1366         </div>
    1367 
    1368         <?php comment_text() ?>
    1369 
    1370         <div class="reply">
    1371         <?php comment_reply_link(array_merge( $args, array('add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
    1372         </div>
    1373         <?php if ( 'div' != $args['style'] ) : ?>
    1374         </div>
    1375         <?php endif; ?>
    1376 <?php
    13771345    }
    13781346
     
    13861354     * @param array $args
    13871355     */
    1388     function end_el(&$output, $comment, $depth = 0, $args = array() ) {
    1389         if ( !empty($args['end-callback']) ) {
    1390             call_user_func($args['end-callback'], $comment, $args, $depth);
     1356    function end_el( &$output, $comment, $depth = 0, $args = array() ) {
     1357        if ( !empty( $args['end-callback'] ) ) {
     1358            call_user_func( $args['end-callback'], $comment, $args, $depth );
    13911359            return;
    13921360        }
    13931361        if ( 'div' == $args['style'] )
    1394             echo "</div>\n";
     1362            echo "</div><!-- #comment-## -->\n";
    13951363        else
    1396             echo "</li>\n";
    1397     }
    1398 
     1364            echo "</li><!-- #comment-## -->\n";
     1365    }
     1366
     1367    /**
     1368     * @since 3.6
     1369     * @access protected
     1370     *
     1371     * @param object $comment
     1372     * @param int $depth Depth of comment.
     1373     * @param array $args
     1374     */
     1375    protected function ping( $comment, $depth, $args ) {
     1376        $tag = ( 'div' == $args['style'] ) ? 'div' : 'li';
     1377?>
     1378        <<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class(); ?>>
     1379            <div class="comment-body">
     1380                <?php _e( 'Pingback:' ); ?> <?php comment_author_link(); ?> <?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?>
     1381            </div>
     1382<?php
     1383    }
     1384
     1385    /**
     1386     * @since 3.6
     1387     * @access protected
     1388     *
     1389     * @param object $comment Comment to display.
     1390     * @param int $depth Depth of comment.
     1391     * @param array $args Optional args.
     1392     */
     1393    protected function comment( $comment, $depth, $args ) {
     1394        if ( 'div' == $args['style'] ) {
     1395            $tag = 'div';
     1396            $add_below = 'comment';
     1397        } else {
     1398            $tag = 'li';
     1399            $add_below = 'div-comment';
     1400        }
     1401?>
     1402        <<?php echo $tag; ?> <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?> id="comment-<?php comment_ID(); ?>">
     1403        <?php if ( 'div' != $args['style'] ) : ?>
     1404        <div id="div-comment-<?php comment_ID(); ?>" class="comment-body">
     1405        <?php endif; ?>
     1406        <div class="comment-author vcard">
     1407            <?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, $args['avatar_size'] ); ?>
     1408            <?php printf( __( '<cite class="fn">%s</cite> <span class="says">says:</span>' ), get_comment_author_link() ); ?>
     1409        </div>
     1410        <?php if ( '0' == $comment->comment_approved ) : ?>
     1411        <em class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ) ?></em>
     1412        <br />
     1413        <?php endif; ?>
     1414
     1415        <div class="comment-meta commentmetadata"><a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
     1416            <?php
     1417                /* translators: 1: date, 2: time */
     1418                printf( __( '%1$s at %2$s' ), get_comment_date(),  get_comment_time() ); ?></a><?php edit_comment_link( __( '(Edit)' ), '&nbsp;&nbsp;', '' );
     1419            ?>
     1420        </div>
     1421
     1422        <?php comment_text() ?>
     1423
     1424        <div class="reply">
     1425            <?php comment_reply_link( array_merge( $args, array( 'add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
     1426        </div>
     1427        <?php if ( 'div' != $args['style'] ) : ?>
     1428        </div>
     1429        <?php endif; ?>
     1430<?php
     1431    }
     1432
     1433    /**
     1434     * @since 3.6
     1435     * @access protected
     1436     *
     1437     * @param object $comment Comment to display.
     1438     * @param int $depth Depth of comment.
     1439     * @param array $args Optional args.
     1440     */
     1441    protected function html5_comment( $comment, $depth, $args ) {
     1442        $tag = ( 'div' === $args['style'] ) ? 'div' : 'li';
     1443?>
     1444        <<?php echo $tag; ?> id="comment-<?php comment_ID(); ?>" <?php comment_class( empty( $args['has_children'] ) ? '' : 'parent' ); ?>>
     1445            <article id="div-comment-<?php comment_ID(); ?>" class="comment-body">
     1446                <footer class="comment-meta">
     1447                    <div class="comment-author vcard">
     1448                        <?php if ( 0 != $args['avatar_size'] ) echo get_avatar( $comment, $args['avatar_size'] ); ?>
     1449                        <?php printf( __( '%s <span class="says">says:</span>' ), sprintf( '<cite class="fn">%s</cite>', get_comment_author_link() ) ); ?>
     1450                    </div><!-- .comment-author -->
     1451
     1452                    <div class="comment-metadata">
     1453                        <a href="<?php echo esc_url( get_comment_link( $comment->comment_ID ) ); ?>">
     1454                            <time datetime="<?php comment_time( 'c' ); ?>">
     1455                                <?php printf( _x( '%1$s at %2$s', '1: date, 2: time' ), get_comment_date(), get_comment_time() ); ?>
     1456                            </time>
     1457                        </a>
     1458                        <?php edit_comment_link( __( 'Edit' ), '<span class="edit-link">', '</span>' ); ?>
     1459                    </div><!-- .comment-metadata -->
     1460
     1461                    <?php if ( '0' == $comment->comment_approved ) : ?>
     1462                    <p class="comment-awaiting-moderation"><?php _e( 'Your comment is awaiting moderation.' ); ?></p>
     1463                    <?php endif; ?>
     1464                </footer><!-- .comment-meta -->
     1465
     1466                <div class="comment-content">
     1467                    <?php comment_text(); ?>
     1468                </div><!-- .comment-content -->
     1469
     1470                <div class="reply">
     1471                    <?php comment_reply_link( array_merge( $args, array( 'add_below' => 'div-comment', 'depth' => $depth, 'max_depth' => $args['max_depth'] ) ) ); ?>
     1472                </div><!-- .reply -->
     1473            </article><!-- .comment-body -->
     1474<?php
     1475    }
    13991476}
    14001477
     
    14181495    $comment_depth = 1;
    14191496
    1420     $defaults = array('walker' => null, 'max_depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all',
    1421         'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => '');
     1497    $defaults = array(
     1498        'walker'            => null,
     1499        'max_depth'         => '',
     1500        'style'             => 'ul',
     1501        'callback'          => null,
     1502        'end-callback'      => null,
     1503        'type'              => 'all',
     1504        'page'              => '',
     1505        'per_page'          => '',
     1506        'avatar_size'       => 32,
     1507        'reverse_top_level' => null,
     1508        'reverse_children'  => '',
     1509        'format'            => 'xhtml', // or html5
     1510        'short_ping'        => false,
     1511    );
    14221512
    14231513    $r = wp_parse_args( $args, $defaults );
Note: See TracChangeset for help on using the changeset viewer.