The effect I want to achieve - at least at this point - is simply to have the comment reply link continue to appear below posts even after "max_depth" for threaded comments has been reached. Though eventually I might like to build more interesting possibilities into the new "infinite threaded comments" function, just having this much achieved would be a big advance for many busy blogs with threaded comments. (In fact, I think it would be a better default functionality than the current one, which is for threads to hit the wall, leaving it to users either to reply to a prior comment or start a new thread, both of which alternatives are clumsy and disadvantageous.)
It turns out that this is simple to achieve, as a blogger reported earlier this year (2014) at http://ift.tt/1rpWM9H : Just delete or comment out the following lines in comment_template.php, under the get_comment_reply_link function:
if ( 0 == $args['depth'] || $args['max_depth'] <= $args['depth'] ) {
return;
}
It works fine: Now, when we reach max-depth on the threaded comments, we can continue to reply in a non-threaded way "infinitely." However, deleting these lines means altering WP core files.
I've tried a number of different solutions after reading through Stack Overflow and searching the codex and so on. My most recent attempt, which I offer not because I have any reason to believe it's the closest I've come, but because at least it doesn't throw fatal errors, is as follows:
function new_get_comment_reply_link( $args = array(), $comment = null, $post = null ) {
$defaults = array(
'add_below' => 'comment',
'respond_id' => 'respond',
'reply_text' => __('Reply'),
'login_text' => __('Log in to Reply'),
'depth' => 0,
'before' => '',
'after' => ''
);
$args = wp_parse_args( $args, $defaults );
if ( 0 == $args['depth'] || $args['max_depth'] <= $args['depth'] ) {
$add_below = $args['add_below'];
$respond_id = $args['respond_id'];
$reply_text = $args['reply_text'];
$comment = get_comment( $comment );
if ( empty( $post ) ) {
$post = $comment->comment_post_ID;
}
$post = get_post( $post );
if ( ! comments_open( $post->ID ) ) {
return false;
}
if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) {
$link = '<a rel="nofollow" class="comment-reply-login" href="' . esc_url( wp_login_url( get_permalink() ) ) . '">' . $args['login_text'] . '</a>';
} else {
$link = "<a class='comment-reply-link' href='" . esc_url( add_query_arg( 'replytocom', $comment->comment_ID ) ) . "#" . $respond_id . "' onclick='return addComment.moveForm(\"$add_below-$comment->comment_ID\", \"$comment->comment_ID\", \"$respond_id\", \"$post->ID\")'>$reply_text</a>";
}
/**
* Filter the comment reply link.
*
* @since 2.7.0
*
* @param string $link The HTML markup for the comment reply link.
* @param array $args An array of arguments overriding the defaults.
* @param object $comment The object of the comment being replied.
* @param WP_Post $post The WP_Post object.
*/
return apply_filters( 'new_comment_reply_link', $args['before'] . $link . $args['after'], $args, $comment, $post );
}
}
function new_comment_reply_link($args = array(), $comment = null, $post = null) {
echo new_get_comment_reply_link($args, $comment, $post);
}
add_filter('get_comment_reply_link','new_get_comment_reply_link',10);
add_filter('comment_reply_link','new_comment_reply_link',10);
To save you a trip comment_template.php at http://ift.tt/13KIxBr , I've taken the code that appears there from lines 1332 - 1446 at this linked version of the core file, a portion that I I believe has not changed in several years, and have tried to hook in two new functions that repeat everything, but this time the "return" removed, and the final bracket moved down. In other words, "If the conditions arise that normally cancel the reply link, let the reply link appear anyway." Note: I've also tried putting the add_filters first, as is I think more often done.
Doesn't work. I've also tried removing the if statement and return entirely, removing the old functions, changing the variables, etc. It looks like it should be the simplest thing in the world, but I'm stumped, and wondering if I should be trying some completely different strategy.
Aucun commentaire:
Enregistrer un commentaire