Changeset 34735 for trunk/src/wp-includes/comment-template.php
- Timestamp:
- 10/01/2015 05:12:39 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/comment-template.php
r34729 r34735 660 660 * 661 661 * @since 1.5.0 662 * @since 4.4.0 Added the ability for `$comment` to also accept a WP_Comment object. 662 * @since 4.4.0 Added the ability for `$comment` to also accept a WP_Comment object. Added `$cpage` argument. 663 663 * 664 664 * @see get_page_of_comment() … … 671 671 * An array of optional arguments to override the defaults. 672 672 * 673 * @type string $type Passed to {@see get_page_of_comment()}. 674 * @type int $page Current page of comments, for calculating comment pagination. 675 * @type int $per_page Per-page value for comment pagination. 676 * @type int $max_depth Passed to {@see get_page_of_comment()}. 673 * @type string $type Passed to {@see get_page_of_comment()}. 674 * @type int $page Current page of comments, for calculating comment pagination. 675 * @type int $per_page Per-page value for comment pagination. 676 * @type int $max_depth Passed to {@see get_page_of_comment()}. 677 * @type int|string $cpage Value to use for the comment's "comment-page" or "cpage" value. If provided, this 678 * value overrides any value calculated from `$page` and `$per_page`. 677 679 * } 678 680 * @return string The permalink to the given comment. … … 688 690 } 689 691 690 $defaults = array( 'type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '' ); 692 $defaults = array( 693 'type' => 'all', 694 'page' => '', 695 'per_page' => '', 696 'max_depth' => '', 697 'cpage' => null, 698 ); 691 699 $args = wp_parse_args( $args, $defaults ); 692 700 693 if ( '' === $args['per_page'] ) 694 $args['per_page'] = get_option('comments_per_page'); 695 696 if ( empty($args['per_page']) ) { 697 $args['per_page'] = 0; 698 $args['page'] = 0; 699 } 700 701 if ( $args['per_page'] ) { 702 if ( '' == $args['page'] ) 703 $args['page'] = ( !empty($in_comment_loop) ) ? get_query_var('cpage') : get_page_of_comment( $comment->comment_ID, $args ); 704 705 if ( $wp_rewrite->using_permalinks() ) 706 $link = user_trailingslashit( trailingslashit( get_permalink( $comment->comment_post_ID ) ) . $wp_rewrite->comments_pagination_base . '-' . $args['page'], 'comment' ); 707 else 708 $link = add_query_arg( 'cpage', $args['page'], get_permalink( $comment->comment_post_ID ) ); 701 $link = get_permalink( $comment->comment_post_ID ); 702 703 // The 'cpage' param takes precedence. 704 if ( ! is_null( $args['cpage'] ) ) { 705 $cpage = $args['cpage']; 706 707 // No 'cpage' is provided, so we calculate one. 709 708 } else { 710 $link = get_permalink( $comment->comment_post_ID ); 709 if ( '' === $args['per_page'] ) { 710 $args['per_page'] = get_option('comments_per_page'); 711 } 712 713 if ( empty( $args['per_page'] ) ) { 714 $args['per_page'] = 0; 715 $args['page'] = 0; 716 } 717 718 $cpage = $args['page']; 719 720 if ( '' == $cpage ) { 721 if ( ! empty( $in_comment_loop ) ) { 722 $cpage = get_query_var( 'cpage' ); 723 } else { 724 // Requires a database hit, so we only do it when we can't figure out from context. 725 $cpage = get_page_of_comment( $comment->comment_ID, $args ); 726 } 727 } 728 729 // Drop the 'page' var if we're on the default page. 730 $comment_post = get_post( $comment->comment_post_ID ); 731 if ( $args['per_page'] ) { 732 $total_pages = ceil( $comment_post->comment_count / $args['per_page'] ); 733 } else { 734 $total_pages = 1; 735 } 736 737 /* 738 * If the default page displays the oldest comments, the permalinks for comments on the default page 739 * do not need a 'cpage' query var. 740 */ 741 $default_comments_page = get_option( 'default_comments_page' ); 742 if ( 'oldest' === get_option( 'default_comments_page' ) && 1 === $cpage ) { 743 $cpage = ''; 744 } 745 } 746 747 if ( $cpage ) { 748 if ( $wp_rewrite->using_permalinks() ) { 749 if ( $cpage ) { 750 $link = trailingslashit( $link ) . $wp_rewrite->comments_pagination_base . '-' . $cpage; 751 } 752 753 $link = user_trailingslashit( $link, 'comment' ); 754 } elseif ( $cpage ) { 755 $link = add_query_arg( 'cpage', $cpage, $link ); 756 } 757 758 } 759 760 if ( $wp_rewrite->using_permalinks() ) { 761 $link = user_trailingslashit( $link, 'comment' ); 711 762 } 712 763 713 764 $link = $link . '#comment-' . $comment->comment_ID; 765 714 766 /** 715 767 * Filter the returned single comment permalink. 716 768 * 717 769 * @since 2.8.0 770 * @since 4.4.0 Added the `$cpage` parameter. 718 771 * 719 772 * @see get_page_of_comment() … … 722 775 * @param WP_Comment $comment The current comment object. 723 776 * @param array $args An array of arguments to override the defaults. 724 */ 725 return apply_filters( 'get_comment_link', $link, $comment, $args ); 777 * @param int $cpage The calculated 'cpage' value. 778 */ 779 return apply_filters( 'get_comment_link', $link, $comment, $args, $cpage ); 726 780 } 727 781 … … 1878 1932 1879 1933 // Pagination is already handled by `WP_Comment_Query`, so we tell Walker not to bother. 1880 if ( 1 < $wp_query->max_num_comment_pages ) { 1881 $r['page'] = 1; 1934 if ( $wp_query->max_num_comment_pages ) { 1935 $default_comments_page = get_option( 'default_comments_page' ); 1936 $cpage = get_query_var( 'cpage' ); 1937 if ( 'newest' === $default_comments_page ) { 1938 $r['cpage'] = $cpage; 1939 1940 // When first page shows oldest comments, post permalink is the same as the comment permalink. 1941 } elseif ( $cpage == 1 ) { 1942 $r['cpage'] = ''; 1943 } else { 1944 $r['cpage'] = $cpage; 1945 } 1946 1947 $r['page'] = 0; 1948 $r['per_page'] = 0; 1882 1949 } 1883 1950 }
Note: See TracChangeset
for help on using the changeset viewer.