Make WordPress Core

Ticket #38925: 38925.2.patch

File 38925.2.patch, 7.9 KB (added by birgire, 8 years ago)
  • src/wp-includes/comment-template.php

     
    15651565/**
    15661566 * Retrieve HTML content for reply to comment link.
    15671567 *
    1568  * @since 2.7.0
     1568 * @since 2.7.0 
    15691569 * @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.
    15701571 *
    15711572 * @param array $args {
    15721573 *     Optional. Override default arguments.
    15731574 *
    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.
    15871589 * }
    15881590 * @param int|WP_Comment $comment Comment being replied to. Default current comment.
    15891591 * @param int|WP_Post    $post    Post ID or WP_Post object the comment is going to be displayed on.
     
    15921594 */
    15931595function get_comment_reply_link( $args = array(), $comment = null, $post = null ) {
    15941596        $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' ),
    15981600                /* 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,
    16051608        );
    16061609
    16071610        $args = wp_parse_args( $args, $defaults );
    16081611
    1609         if ( 0 == $args['depth'] || $args['max_depth'] <= $args['depth'] ) {
     1612        $depth = $args['depth'];
     1613
     1614        if ( 0 == $depth ) {
    16101615                return;
    16111616        }
    16121617
     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
    16131634        $comment = get_comment( $comment );
    16141635
     1636        if( empty( $comment ) ) {
     1637                 return;
     1638        }
     1639
    16151640        if ( empty( $post ) ) {
    16161641                $post = $comment->comment_post_ID;
    16171642        }
     
    16221647                return false;
    16231648        }
    16241649
    1625         /**
    1626          * Filters the comment reply link arguments.
    1627          *
    1628          * @since 4.1.0
    1629          *
    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 
    16371650        if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) {
    16381651                $link = sprintf( '<a rel="nofollow" class="comment-reply-login" href="%s">%s</a>',
    16391652                        esc_url( wp_login_url( get_permalink() ) ),
  • tests/phpunit/tests/comment/getCommentReplyLink.php

     
    2626
    2727                $this->assertNull( get_comment_reply_link( $args ) );
    2828        }
     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
    2980}