Ticket #38925: 38925.2.patch
File 38925.2.patch, 7.9 KB (added by , 8 years ago) |
---|
-
src/wp-includes/comment-template.php
1565 1565 /** 1566 1566 * Retrieve HTML content for reply to comment link. 1567 1567 * 1568 * @since 2.7.0 1568 * @since 2.7.0 1569 1569 * @since 4.4.0 Added the ability for `$comment` to also accept a WP_Comment object. 1570 * @since 4.9.0 Added the `$limit_by_depth` argument, whether to hide the link at the max depth and below. 1570 1571 * 1571 1572 * @param array $args { 1572 1573 * Optional. Override default arguments. 1573 1574 * 1574 * @type string $add_below The first part of the selector used to identify the comment to respond below. 1575 * The resulting value is passed as the first parameter to addComment.moveForm(), 1576 * concatenated as $add_below-$comment->comment_ID. Default 'comment'. 1577 * @type string $respond_id The selector identifying the responding comment. Passed as the third parameter 1578 * to addComment.moveForm(), and appended to the link URL as a hash value. 1579 * Default 'respond'. 1580 * @type string $reply_text The text of the Reply link. Default 'Reply'. 1581 * @type string $login_text The text of the link to reply if logged out. Default 'Log in to Reply'. 1582 * @type int $max_depth The max depth of the comment tree. Default 0. 1583 * @type int $depth The depth of the new comment. Must be greater than 0 and less than the value 1584 * of the 'thread_comments_depth' option set in Settings > Discussion. Default 0. 1585 * @type string $before The text or HTML to add before the reply link. Default empty. 1586 * @type string $after The text or HTML to add after the reply link. Default empty. 1575 * @type string $add_below The first part of the selector used to identify the comment to respond below. 1576 * The resulting value is passed as the first parameter to addComment.moveForm(), 1577 * concatenated as $add_below-$comment->comment_ID. Default 'comment'. 1578 * @type string $respond_id The selector identifying the responding comment. Passed as the third parameter 1579 * to addComment.moveForm(), and appended to the link URL as a hash value. 1580 * Default 'respond'. 1581 * @type string $reply_text The text of the Reply link. Default 'Reply'. 1582 * @type string $login_text The text of the link to reply if logged out. Default 'Log in to Reply'. 1583 * @type int $max_depth The max depth of the comment tree. Default 0. 1584 * @type int $depth The depth of the new comment. Must be greater than 0 and less than the value 1585 * of the 'thread_comments_depth' option set in Settings > Discussion. Default 0. 1586 * @type string $before The text or HTML to add before the reply link. Default empty. 1587 * @type string $after The text or HTML to add after the reply link. Default empty. 1588 * @type bool $limit_by_depth Hide the link at the max depth and below. Default true. 1587 1589 * } 1588 1590 * @param int|WP_Comment $comment Comment being replied to. Default current comment. 1589 1591 * @param int|WP_Post $post Post ID or WP_Post object the comment is going to be displayed on. … … 1592 1594 */ 1593 1595 function get_comment_reply_link( $args = array(), $comment = null, $post = null ) { 1594 1596 $defaults = array( 1595 'add_below' => 'comment',1596 'respond_id' => 'respond',1597 'reply_text' => __( 'Reply' ),1597 'add_below' => 'comment', 1598 'respond_id' => 'respond', 1599 'reply_text' => __( 'Reply' ), 1598 1600 /* translators: Comment reply button text. 1: Comment author name */ 1599 'reply_to_text' => __( 'Reply to %s' ), 1600 'login_text' => __( 'Log in to Reply' ), 1601 'max_depth' => 0, 1602 'depth' => 0, 1603 'before' => '', 1604 'after' => '' 1601 'reply_to_text' => __( 'Reply to %s' ), 1602 'login_text' => __( 'Log in to Reply' ), 1603 'max_depth' => 0, 1604 'depth' => 0, 1605 'before' => '', 1606 'after' => '', 1607 'limit_by_depth' => true, 1605 1608 ); 1606 1609 1607 1610 $args = wp_parse_args( $args, $defaults ); 1608 1611 1609 if ( 0 == $args['depth'] || $args['max_depth'] <= $args['depth'] ) { 1612 $depth = $args['depth']; 1613 1614 if ( 0 == $depth ) { 1610 1615 return; 1611 1616 } 1612 1617 1618 /** 1619 * Filters the comment reply link arguments. 1620 * 1621 * @since 4.1.0 1622 * 1623 * @param array $args Comment reply link arguments. See get_comment_reply_link() 1624 * for more information on accepted arguments. 1625 * @param WP_Comment $comment The object of the comment being replied to. 1626 * @param WP_Post $post The WP_Post object. 1627 */ 1628 $args = apply_filters( 'comment_reply_link_args', $args, $comment, $post ); 1629 1630 if ( $args['limit_by_depth'] && ( $args['max_depth'] <= $depth ) ) { 1631 return; 1632 } 1633 1613 1634 $comment = get_comment( $comment ); 1614 1635 1636 if( empty( $comment ) ) { 1637 return; 1638 } 1639 1615 1640 if ( empty( $post ) ) { 1616 1641 $post = $comment->comment_post_ID; 1617 1642 } … … 1622 1647 return false; 1623 1648 } 1624 1649 1625 /**1626 * Filters the comment reply link arguments.1627 *1628 * @since 4.1.01629 *1630 * @param array $args Comment reply link arguments. See get_comment_reply_link()1631 * for more information on accepted arguments.1632 * @param WP_Comment $comment The object of the comment being replied to.1633 * @param WP_Post $post The WP_Post object.1634 */1635 $args = apply_filters( 'comment_reply_link_args', $args, $comment, $post );1636 1637 1650 if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) { 1638 1651 $link = sprintf( '<a rel="nofollow" class="comment-reply-login" href="%s">%s</a>', 1639 1652 esc_url( wp_login_url( get_permalink() ) ), -
tests/phpunit/tests/comment/getCommentReplyLink.php
26 26 27 27 $this->assertNull( get_comment_reply_link( $args ) ); 28 28 } 29 30 /** 31 * @ticket 38925 32 */ 33 public function test_should_return_reply_link_when_limit_by_depth_is_false_and_max_depth_less_than_depth() { 34 35 $post_id = self::factory()->post->create(); 36 $comment_id = self::factory()->comment->create( array( 'comment_post_ID' => $post_id, 'comment_approved' => '1' ) ); 37 38 $args = array( 39 'depth' => 5, 40 'max_depth' => 4, 41 'limit_by_depth' => false, 42 ); 43 44 $this->assertContains( 'replytocom', get_comment_reply_link( $args, $comment_id ) ); 45 } 46 47 /** 48 * @ticket 38925 49 */ 50 public function test_should_return_reply_link_when_limit_by_depth_is_true_and_depth_less_than_max_depth() { 51 52 $post_id = self::factory()->post->create(); 53 $comment_id = self::factory()->comment->create( array( 'comment_post_ID' => $post_id, 'comment_approved' => '1' ) ); 54 55 $args = array( 56 'depth' => 4, 57 'max_depth' => 5, 58 'limit_by_depth' => true, 59 ); 60 61 $this->assertContains( 'replytocom', get_comment_reply_link( $args, $comment_id ) ); 62 } 63 64 /** 65 * @ticket 38925 66 */ 67 public function test_should_return_false_on_post_with_closed_comment_status() { 68 69 $post_id = self::factory()->post->create( array( 'comment_status' => 'closed' ) ); 70 $comment_id = self::factory()->comment->create( array( 'comment_post_ID' => $post_id, 'comment_approved' => '1' ) ); 71 72 $args = array( 73 'depth' => 4, 74 'max_depth' => 5, 75 ); 76 77 $this->assertFalse( get_comment_reply_link( $args, $comment_id ) ); 78 } 79 29 80 }