I need to edit the function get_comment_reply_link() in wp-includes/comments-template.php. All I really wanna do is take out the “log in to reply” text is puts in every comment for logged out users which is disturbing to me. How can I do this the right way? Here’s the function.
function get_comment_reply_link($args = array(), $comment = null, $post = null) {
global $user_ID;
$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'] )
return;
extract($args, EXTR_SKIP);
$comment = get_comment($comment);
if ( empty($post) )
$post = $comment->comment_post_ID;
$post = get_post($post);
if ( !comments_open($post->ID) )
return false;
$link = '';
if ( get_option('comment_registration') && !$user_ID )
$link = '<a rel="nofollow" class="comment-reply-login" href="' . esc_url( wp_login_url( get_permalink() ) ) . '" rel="nofollow noreferrer noopener">' . $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>";
return apply_filters('comment_reply_link', $before . $link . $after, $args, $comment, $post);
}
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
You can filter the output for the comment reply link on … wait for it! … 'comment_reply_link'. Just do the same checks as the core function but return something else, in your case: nothing.
<?php # -*- coding: utf-8 -*-
/**
* Plugin Name: T5 No Comment Log In Link
* Plugin URI: http://wordpress.stackexchange.com/q/52350/73
* Description: Removes the log-in link for comment reply links.
* Version: 2012.05.16
* Author: Thomas Scholz <<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0b62656d644b7f6478686364256f6e">[email protected]</a>>
* Author URI: http://toscho.de
* License: MIT
* License URI: http://www.opensource.org/licenses/mit-license.php
*/
if ( ! function_exists( 't5_do_not_ask_for_comment_log_in' ) )
{
add_filter( 'comment_reply_link', 't5_do_not_ask_for_comment_log_in' );
/**
* Replaces the log-in link with an empty string.
*
* @param string $link
* @return string
*/
function t5_do_not_ask_for_comment_log_in( $link )
{
if ( empty ( $GLOBALS['user_ID'] ) && get_option( 'comment_registration' ) )
{
return '';
}
return $link;
}
}
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0