Make WordPress Core


Ignore:
Timestamp:
11/20/2008 06:41:55 AM (17 years ago)
Author:
markjaquith
Message:

Improvements for get_comment_link() from Viper007Bond. fixes #8287

File:
1 edited

Legend:

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

    r9781 r9808  
    442442 *
    443443 * @param object|string|int $comment Comment to retrieve.
    444  * @param string|int $page The comment's page if known. Optional. Avoids extra database query.
     444 * @param array $args Optional args.
    445445 * @return string The permalink to the current comment
    446446 */
    447 function get_comment_link( $comment = null, $page = null ) {
    448     global $wp_rewrite;
     447function get_comment_link( $comment = null, $args = array() ) {
     448    global $wp_rewrite, $in_comment_loop;
    449449
    450450    $comment = get_comment($comment);
    451451
    452     if ( get_option('page_comments') ) {
    453         $page = ( null !== $page ) ? (int) $page : get_page_of_comment( $comment->comment_ID );
     452    // Backwards compat
     453    if ( !is_array($args) ) {
     454        $page = $args;
     455        $args = array();
     456        $args['page'] = $page;
     457    }
     458
     459    $defaults = array( 'type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '' );
     460    $args = wp_parse_args( $args, $defaults );
     461
     462    if ( '' === $args['per_page'] && get_option('page_comments') )
     463        $args['per_page'] = get_query_var('comments_per_page');
     464
     465    if ( empty($args['per_page']) ) {
     466        $args['per_page'] = 0;
     467        $args['page'] = 0;
     468    }
     469
     470    if ( $args['per_page'] ) {
     471        if ( '' == $args['page'] )
     472            $args['page'] = ( !empty($in_comment_loop) ) ? get_query_var('cpage') : get_page_of_comment( $comment->comment_ID, $args );
    454473
    455474        if ( $wp_rewrite->using_permalinks() )
    456             return user_trailingslashit( trailingslashit( get_permalink( $comment->comment_post_ID ) ) . "comment-page-$page", 'comment' ) . '#comment-' . $comment->comment_ID;
     475            return user_trailingslashit( trailingslashit( get_permalink( $comment->comment_post_ID ) ) . 'comment-page-' . $args['page'], 'comment' ) . '#comment-' . $comment->comment_ID;
    457476        else
    458             return add_query_arg( 'cpage', $page, get_permalink( $comment->comment_post_ID ) ) . '#comment-' . $comment->comment_ID;
     477            return add_query_arg( 'cpage', $args['page'], get_permalink( $comment->comment_post_ID ) ) . '#comment-' . $comment->comment_ID;
    459478    } else {
    460479        return get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID;
     
    11631182<?php endif; ?>
    11641183
    1165         <div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID, $page ) ) ?>"><?php printf(__('%1$s at %2$s'), get_comment_date('F jS, Y'),  get_comment_time()) ?></a><?php edit_comment_link('edit','&nbsp;&nbsp;','') ?></div>
     1184        <div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>"><?php printf(__('%1$s at %2$s'), get_comment_date('F jS, Y'),  get_comment_time()) ?></a><?php edit_comment_link('edit','&nbsp;&nbsp;','') ?></div>
    11661185
    11671186        <?php comment_text() ?>
     
    12101229 */
    12111230function wp_list_comments($args = array(), $comments = null ) {
    1212     global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage;
     1231    global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
     1232
     1233    $in_comment_loop = true;
    12131234
    12141235    $comment_alt = $comment_thread_alt = 0;
     
    12861307    $walker->paged_walk($_comments, $max_depth, $page, $per_page, $r);
    12871308    $wp_query->max_num_comment_pages = $walker->max_pages;
     1309
     1310    $in_comment_loop = false;
    12881311}
    12891312
Note: See TracChangeset for help on using the changeset viewer.