返回介绍

get_comment_reply_link()

发布于 2017-09-10 23:08:08 字数 6332 浏览 1032 评论 0 收藏 0

get_comment_reply_link( array $args = array(),  int|WP_Comment $comment = null,  int|WP_Post $post = null )

Retrieve HTML content for reply to comment link.


description


参数

$args

(array) (Optional) Override default arguments.

  • 'add_below'
    (string) The first part of the selector used to identify the comment to respond below. The resulting value is passed as the first parameter to addComment.moveForm(), concatenated as $add_below-$comment->comment_ID. Default 'comment'.
  • 'respond_id'
    (string) The selector identifying the responding comment. Passed as the third parameter to addComment.moveForm(), and appended to the link URL as a hash value. Default 'respond'.
  • 'reply_text'
    (string) The text of the Reply link. Default 'Reply'.
  • 'login_text'
    (string) The text of the link to reply if logged out. Default 'Log in to Reply'.
  • 'max_depth'
    (int) The max depth of the comment tree. Default 0.
  • 'depth'
    (int) The depth of the new comment. Must be greater than 0 and less than the value of the 'thread_comments_depth' option set in Settings > Discussion. Default 0.
  • 'before'
    (string) The text or HTML to add before the reply link.
  • 'after'
    (string) The text or HTML to add after the reply link.

Default value: array()

$comment

(int|WP_Comment) (Optional) Comment being replied to. Default current comment.

Default value: null

$post

(int|WP_Post) (Optional) Post ID or WP_Post object the comment is going to be displayed on. Default current post.

Default value: null


返回值

(void|false|string) Link to show comment form, if successful. False, if comments are closed.


源代码

File: wp-includes/comment-template.php

function get_comment_reply_link( $args = array(), $comment = null, $post = null ) {
	$defaults = array(
		'add_below'     => 'comment',
		'respond_id'    => 'respond',
		'reply_text'    => __( 'Reply' ),
		/* translators: Comment reply button text. 1: Comment author name */
		'reply_to_text' => __( 'Reply to %s' ),
		'login_text'    => __( 'Log in to Reply' ),
		'max_depth'     => 0,
		'depth'         => 0,
		'before'        => '',
		'after'         => ''
	);

	$args = wp_parse_args( $args, $defaults );

	if ( 0 == $args['depth'] || $args['max_depth'] <= $args['depth'] ) {
		return;
	}

	$comment = get_comment( $comment );

	if ( empty( $post ) ) {
		$post = $comment->comment_post_ID;
	}

	$post = get_post( $post );

	if ( ! comments_open( $post->ID ) ) {
		return false;
	}

	/**
	 * Filters the comment reply link arguments.
	 *
	 * @since 4.1.0
	 *
	 * @param array      $args    Comment reply link arguments. See get_comment_reply_link()
	 *                            for more information on accepted arguments.
	 * @param WP_Comment $comment The object of the comment being replied to.
	 * @param WP_Post    $post    The WP_Post object.
	 */
	$args = apply_filters( 'comment_reply_link_args', $args, $comment, $post );

	if ( get_option( 'comment_registration' ) && ! is_user_logged_in() ) {
		$link = sprintf( '<a rel="nofollow" class="comment-reply-login" href="%s">%s</a>',
			esc_url( wp_login_url( get_permalink() ) ),
			$args['login_text']
		);
	} else {
		$onclick = sprintf( 'return addComment.moveForm( "%1$s-%2$s", "%2$s", "%3$s", "%4$s" )',
			$args['add_below'], $comment->comment_ID, $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_ID, get_permalink( $post->ID ) ) ) . "#" . $args['respond_id'],
			$onclick,
			esc_attr( sprintf( $args['reply_to_text'], $comment->comment_author ) ),
			$args['reply_text']
		);
	}

	/**
	 * Filters 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( 'comment_reply_link', $args['before'] . $link . $args['after'], $args, $comment, $post );
}

更新日志

Versiondescription
4.4.0Added the ability for $comment to also accept a WP_Comment object.
2.7.0Introduced.

相关函数

Uses

  • wp-includes/comment-template.php: comment_reply_link_args
  • wp-includes/l10n.php: __()
  • wp-includes/formatting.php: esc_url()
  • wp-includes/formatting.php: esc_attr()
  • wp-includes/pluggable.php: is_user_logged_in()
  • wp-includes/general-template.php: wp_login_url()
  • wp-includes/functions.php: wp_parse_args()
  • wp-includes/functions.php: add_query_arg()
  • wp-includes/link-template.php: get_permalink()
  • wp-includes/plugin.php: apply_filters()
  • wp-includes/option.php: get_option()
  • wp-includes/post.php: get_post()
  • wp-includes/comment-template.php: comment_reply_link
  • wp-includes/comment-template.php: comments_open()
  • wp-includes/comment.php: get_comment()
  • Show 10 more uses Hide more uses

Used By

  • wp-includes/comment-template.php: comment_reply_link()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文