3

As the title says, is there a way to override the default setup where max nest-1 is the last time a "reply" option shows up and enable "reply" at max but switch comments to a flat inline reply after?

Eg,

1 > 2 > 3 > 4 > 4 > 4 etc., where the numbers are the reply-nest levels.

Not only is it irritating for commentors, but whatever rule WP uses to disable replies is also eating the edit and report options.

Thanks!

1 Answer 1

2

Here's one suggestion using the comment_reply_link filter to change the reply links.

Instead of using a regular expression to change it, I think it's easier to just construct the links again.

Here I use the same code as used in the get_comment_reply_link() core function, but I replace the $comment->comment_ID with $comment->comment_parent when the following condition is fulfilled:

max_depth === depth + 1

We can adjust max_depth from the backend settings or via the thread_comments_depth_max filter, where you can e.g. find an example in my answer here.

Here's our demo plugin:

/* Regenerate the reply link but for the comment parent instead */
add_filter( 'comment_reply_link', function( $link, $args, $comment, $post )
{       
    if( 
           isset( $args['depth' ] ) 
        && isset( $args['max_depth' ] )
        && isset( $args['respond_id' ] )
        && isset( $args['add_below' ] )
        && isset( $args['reply_text'] )
        && isset( $args['reply_to_text'] )
        && (int) $args['max_depth'] === 1 + (int) $args['depth' ] 
        && ( ! get_option( 'comment_registration' ) ||  is_user_logged_in() )
    ) {         
         $onclick = sprintf( 
             'return addComment.moveForm( "%1$s-%2$s", "%2$s", "%3$s", "%4$s" )',
             $args['add_below'], $comment->comment_parent, $args['respond_id'], $post->ID
         );

         $link = sprintf( 
             "<a rel='nofollow' class='comment-reply-link' 
                 href='%s' onclick='%s' aria-label='%s'>%s</a>",
            esc_url( 
                add_query_arg( 
                    'replytocom', 
                     $comment->comment_parent, 
                     get_permalink( $post->ID ) 
                ) 
            ) . "#" . $args['respond_id'],
            $onclick,
            esc_attr( 
                sprintf( $args['reply_to_text'], $comment->comment_author )
            ),
            $args['reply_text']
        );
    }
    return $link;
}, 10, 4 );

Hope it helps.

1
  • Thank you for taking the time to do this! This is a total noob question, but where would I insert this code?
    – Act
    Commented Aug 11, 2016 at 16:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.